Search code examples
symfonyassetssymfony4symfony-3.3symfony-3.4

Symfony upgrade to 4.1 assets error


I migrated a project for Symfony 4.1 but did not change the file structure to new Symfony files structure. My assets, for example, remain in the \web folder. It works fine except for assets. To fix this problem I replaced in the controllers:

$this->container->get('templating.helper.assets')->getUrl($path);

to

$this->container->get('assets.packages')->getUrl($path);

I also execute the following command: composer require symfony/asset

After this, when I run the web page I am getting the following error:

The "assets.packages" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

To try to fix this error, I put it in services.yml:

services:
assets.packages:
    class: \Symfony\Component\Asset\Packages
    public: true

But after that I get another error:

enter image description here

Do you have any idea what that might be? Is something wrong?


Solution

  • I've been able to fix the error. It was enough to add as argument in the service the default package:

    assets.packages:
        class: \Symfony\Component\Asset\Packages
        arguments: ['@assets._default_package']
        public: true