"assets:install" 命令失败并出现错误 "The target directory "web“不存在”,为什么?

"assets:install" command fails with error "The target directory "web" does not exist", why?

我是 运行 一个位于 Docker 容器中的 Symfony3 应用程序。我创建了一个包含所有资源(js、css、图像)的 CommonBundle。此资源符号链接到另一个路径,如下所示:

$ docker exec -u www-data -it dockeramp_php_1 ls -la oneview_symfony/src/CommonBundle/Resources/public
total 8
drwxrwsr-x 2 www-data www-data 4096 Feb 23 21:09 .
drwxr-sr-x 5 www-data www-data 4096 Feb 23 20:54 ..
lrwxrwxrwx 1 root     www-data   32 Feb 23 21:09 css -> /var/www/html/public_html/styles
lrwxrwxrwx 1 root     www-data   32 Feb 23 21:09 images -> /var/www/html/public_html/images
lrwxrwxrwx 1 root     www-data   28 Feb 23 21:08 js -> /var/www/html/public_html/js

目录 oneview_symfony/web 确实存在并且可以由 www-data 写入,如下所示:

$ docker exec -u www-data -it dockeramp_php_1 ls -la oneview_symfony/web
total 64
drwxrwsr-x 3 www-data www-data  4096 Feb 23 20:50 .
drwxrwsr-x 9 www-data www-data  4096 Feb 23 21:16 ..
-rwxrwxr-x 1 www-data www-data  3319 Feb 23 16:45 .htaccess
-rwxrwxr-x 1 www-data www-data   631 Feb 23 16:45 app.php
-rwxrwxr-x 1 www-data www-data   843 Feb 23 16:45 app_dev.php
-rwxrwxr-x 1 www-data www-data  2092 Feb 23 16:45 apple-touch-icon.png
drwxr-sr-x 2 www-data www-data  4096 Feb 23 20:50 bundles
-rw-rw-rw- 1 www-data www-data 21486 Feb 23 20:50 config.php
-rwxrwxr-x 1 www-data www-data  6518 Feb 23 16:45 favicon.ico
-rwxrwxr-x 1 www-data www-data   116 Feb 23 16:45 robots.tx

我正在尝试在 composer.json 文件上安装资产 relativesymlink 切换值:

{
    ...
    "extra": {
        ... 
        "symfony-web-dir": "web",
        "symfony-assets-install": "relative",
    }
}

我正在尝试发布资产 运行 以下命令并以以下错误结束:

$ docker exec -u www-data -it dockeramp_php_1 php oneview_symfony/bin/console assets:install


  [InvalidArgumentException]                  
  The target directory "web" does not exist.

我在这里缺少什么?

有一个类似的问题here但目前还没有答案。

你能试试这个命令吗:

$ docker exec -u www-data -it dockeramp_php_1 php oneview_symfony/bin/console assets:install web

如果这不起作用,请尝试 web 目录的完整路径。 让我们知道这是否有效。不确定这是否会解决问题,但请尝试一下。

任何试图在 Symfony 4 中使用旧的 Symfony3 目录结构安装资产的人:

Error thrown while running command "assets:install". Message: "The target directory "public" does not exist."

Alvin Bunk 提供的相同修复有效:

$ bin/console assets:install web

只需手动提供旧的目标路径

您需要 运行 确切的行

app/console assets:installbin/console assets:install

(取决于你的版本)因为它以命令的路径作为参考。

assets 命令配置变量。

public-dir 添加到 composer.json

"extra": {
    "symfony-web-dir": "web",
    "public-dir": "web",
    ...
},

因为assets命令依赖它(view code on github)

看:

        $defaultPublicDir = 'public';

        // ...

        if (isset($composerConfig['extra']['public-dir'])) {
            return $composerConfig['extra']['public-dir'];
        }

        return $defaultPublicDir;