ReynierPM
ReynierPM

Reputation: 18680

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

I am running a Symfony3 application inside a Docker container. I have created a CommonBundle with all the resources (js, css, images). This resources are symlinked to another path as shown below:

$ 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

The directory oneview_symfony/web does exists and it's writable by www-data as shown below:

$ 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

I am trying to install the assets relative or symlink switching values on the composer.json file:

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

I am trying to publish the assets running the following command and ending up with the error below:

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


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

What I am missing here?

There is a similar issue here but without answer so far.

Upvotes: 4

Views: 6323

Answers (4)

Jekis
Jekis

Reputation: 4695

Configure variable for assets command.

Add public-dir to composer.json

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

Because assets command relies on it (view code on github)

Look:

        $defaultPublicDir = 'public';

        // ...

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

        return $defaultPublicDir;

Upvotes: 2

Baldráni
Baldráni

Reputation: 5638

You need to run the exact line

app/console assets:install or bin/console assets:install

(depends on your version) since it takes the path of the command as reference.

Upvotes: 0

Yes Barry
Yes Barry

Reputation: 9876

For anyone trying to install assets in Symfony 4 with the old Symfony3 directory structure getting:

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

The same fix Alvin Bunk provided works:

$ bin/console assets:install web

Just manually provide the old target path

Upvotes: 1

Alvin Bunk
Alvin Bunk

Reputation: 7764

Can you try this command instead:

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

If that doesn't work, try the full path to the web directory. Let us know if that works. Not sure if that will fix the problem, but please try it.

Upvotes: 7

Related Questions