The service "fos_user.mailer" has a dependency on a non-existent service "templating"

Michael Emerson picture Michael Emerson · Dec 4, 2017 · Viewed 25.5k times · Source

So, the above error has suddenly started happening, after I've been using FOSUserBundle for several Symfony projects.

I've tried including the templating service (twice now) and it seems like it's installed fine. Here is my list of requires in my composer.json:

"require": {
    "php": ">=5.5.9",
    "doctrine/doctrine-bundle": "^1.6",
    "doctrine/orm": "^2.5",
    "friendsofsymfony/user-bundle": "^2.0",
    "incenteev/composer-parameter-handler": "^2.0",
    "sensio/distribution-bundle": "^5.0.19",
    "sensio/framework-extra-bundle": "^5.0.0",
    "symfony/monolog-bundle": "^3.1.0",
    "symfony/polyfill-apcu": "^1.0",
    "symfony/swiftmailer-bundle": "^2.6.4",
    "symfony/symfony": "3.4.*",
    "symfony/templating": "^3.4",
    "twig/twig": "^1.0||^2.0"
},

I've set up the config.yml, security.yml and the routing.yml files as per usual, and included the bundle in the AppKernel.php file. I've also created the User.php Entity but every time I try to clear the cache or update the database, I get this error.

The service "fos_user.mailer" has a dependency on a non-existent service "templating"

And after much searching I cannot see where to fix this problem. Any help with this is much appreciated as it's something that's never happened before, and I've always used FOSUserBundle for my security needs.

Answer

Moccine picture Moccine · Dec 22, 2017

In Symfony 3.4 and FosUserBundle 2.0, add a service mailer into the fos_user config:

fos_user:
    db_driver: orm # other valid values are 'mongodb' and 'couchdb'
    firewall_name: main
    user_class: AppBundle\Entity\User
    service:                               # this lines
        mailer: fos_user.mailer.twig_swift # this lines
    from_email:
        address: "%mailer_user%"
        sender_name: "%mailer_user%