Skip to content
Latchkey

Symfony "You have requested a non-existent service" in CI

The Symfony service container was asked for a service id it does not define. The id is wrong, the service was removed or made private, or the bundle that registers it is not loaded in the environment CI runs (often the test env).

What this error means

A command or test fails during container compilation with "You have requested a non-existent service \"X\"." The id in the message is the one the container cannot resolve.

Symfony
In ContainerBuilder.php line 1075:
  You have requested a non-existent service "app.mailer". Did you mean this: "mailer.mailer"?

Common causes

The service id is misspelled or was removed

A reference in a controller, config, or another service points at an id the container never defines. The "Did you mean" hint lists the closest real ids.

The bundle is not enabled in the CI environment

Symfony loads bundles per environment in config/bundles.php. If a bundle is only enabled for dev and CI runs with APP_ENV=test, its services are absent.

How to fix it

List the real service ids and correct the reference

  1. Run bin/console debug:container with the same APP_ENV CI uses to see defined ids.
  2. Fix the reference to match a real id, or make the service public if it is fetched from the container directly.
  3. Re-run the failing command to confirm the id resolves.
Terminal
APP_ENV=test php bin/console debug:container app.mailer

Enable the bundle for the test environment

Add the environment to the bundle entry in config/bundles.php so its services register when CI compiles the container.

config/bundles.php
// config/bundles.php
return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    App\SomeBundle\SomeBundle::class => ['all' => true],
];

How to prevent it

  • Run debug:container with APP_ENV=test locally so missing ids surface before CI.
  • Keep bundle environment maps in config/bundles.php consistent with what tests need.
  • Prefer autowired constructor injection over fetching services by id from the container.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →