# Yii2压缩前端资源时报错问题汇总

**URL:** <https://www.shiqidu.com/t/topic/586>\
**Category:** 开发调优\
**Tags:** Yii\
**Created:** [2019 年5 月 22 日 02:14 UTC](https://www.shiqidu.com/t/topic/586 "2019-05-22T02:14:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2019 年5 月 22 日 02:14 UTC](https://www.shiqidu.com/t/topic/586/1 "2019-05-22T02:14:22Z")

</div>

参考文章 [yii2 asset合并压缩(多个资源文件配置) - 教程 - Yii Framework 中文网](https://www.yiichina.com/tutorial/1496)

#### 首先是各种目录找不到的问题

```shell
Exception 'yii\base\InvalidArgumentException' with message 'The file or directory to be published does not exist: /Applications/MAMP/htdocs/shiqidu.2018.com/vendor/npm/bootstrap4c-chosen'

```

```shell
Exception 'yii\base\InvalidArgumentException' with message 'The file or directory to be published does not exist: /Applications/MAMP/htdocs/shiqidu.2018.com/vendor/bower/bootstrap/dist'

```

`vendor`目录下没有`brower` 和 `npm`这两个目录，真实目录的名字是`bower-asset`和`npm-asset`，所需需要我们设置一下别名。

在`assets.php`文件中添加下面两行。

```php
Yii::setAlias('@bower', __DIR__. '/vendor/bower-asset');
Yii::setAlias('@npm', __DIR__. '/vendor/npm-asset');

```

#### 然后是目录权限问题

```shell
PHP Warning 'yii\base\ErrorException' with message 'file_put_contents(/Applications/MAMP/htdocs/shiqidu.2018.com/web/assets/js/all-temp.js.tmp): failed to open stream: No such file or directory'

```

因为没有权限所以创建目录失败，直接手动在`web/assets`目录下创建`js`目录即可。
