Home » Php » php – Symfony2: InvalidArgumentException: The service definition "templating.helpers.assets" does not exist

php – Symfony2: InvalidArgumentException: The service definition "templating.helpers.assets" does not exist

Posted by: admin July 12, 2020 Leave a comment

Questions:

While working on my Symfony2 project, I (seemingly) randomly got the error InvalidArgumentException: The service definition "templating.helpers.assets" does not exist. when going to any page. I have tried going back to earlier commits, but that doesn’t change anything. So it doesn’t seem to be any of my own source code. I also cannot composer update. I have tried removing the cache, vendor directory, and composer.lock file, but I still get this error:

Loading composer repositories with package information

Updating dependencies (including require-dev)

Generating autoload files

Updating the “app/config/parameters.yml” file

[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException] The service definition “templating.helpers.assets” does not exist.

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception

[RuntimeException] An error occurred when executing the “‘cache:clear –no-warmup'” command.

Any ideas?

How to&Answers:

FYI service templating.helper.assets exist

php app/console container:debug  templating.helper.assets 
[container] Information for service templating.helper.assets
Service Id       templating.helper.assets
Class            Symfony\Component\Templating\Helper\CoreAssetsHelper
Tags
    - templating.helper              (alias: assets)
Scope            request
Public           yes
Synthetic        no
Lazy             no
Synchronized     no
Abstract         no

It is created by Symfony\Bundle\FrameworkBundle\FrameworkBundle()
and defined in Resources\config\templating_php.xml

    <service id="templating.helper.assets" class="%templating.helper.assets.class%">
        <tag name="templating.helper" alias="assets" />
        <argument /> <!-- default package -->
        <argument type="collection" /> <!-- named packages -->
    </service>

So add this bundle in your appKernel.php

public function registerBundles()
{
    $bundles = array(
        //Standard
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        //others bundles