Skip to content
Latchkey

Symfony "Cannot autowire service ... argument references ... but no such service exists" in CI

Autowiring tried to resolve a constructor argument by its type hint and found no service registered for that class or interface. Symfony cannot guess which implementation to inject, so container compilation fails.

What this error means

Compilation fails with "Cannot autowire service \"X\": argument \"$y\" of method \"__construct()\" references interface \"Z\" but no such service exists." Symfony often suggests aliasing the interface.

Symfony
Cannot autowire service "App\Service\Invoicer": argument "$client" of method
"__construct()" references interface "App\Client\PaymentClientInterface" but no such
service exists. Did you create a class that implements this interface?

Diagnose it: version, extensions, and limits

Terminal
php -v
php -m
php -i | grep -E "memory_limit|max_execution_time|error_reporting"

# a runner default is often far tighter than your local php.ini
php -d memory_limit=-1 vendor/bin/<tool>

Common causes

An interface has no service alias

You type-hinted an interface but never told the container which concrete service implements it, so autowiring has nothing to inject.

The class is excluded from autoloading in this env

A resource/exclude rule in services.yaml, or a bundle absent in the test env, means the implementing class is never registered as a service.

How to fix it

Alias the interface to a concrete service

  1. Pick the implementation that should be injected.
  2. Add an alias binding the interface id to that service in services.yaml.
  3. Re-run container compilation to confirm autowiring resolves it.
config/services.yaml
# config/services.yaml
services:
    App\Client\PaymentClientInterface: '@App\Client\StripePaymentClient'

Bind a scalar or named argument explicitly

For arguments autowiring cannot infer (a string, a specific instance), bind them by name so the container stops trying to autowire them.

config/services.yaml
services:
    _defaults:
        bind:
            $client: '@App\Client\StripePaymentClient'

How to prevent it

  • Alias every injectable interface to a concrete implementation.
  • Run lint:container in CI so autowiring gaps fail fast.
  • Keep the same service registration rules across dev and test environments.

Frequently asked questions

What causes Symfony "Cannot autowire service ... argument references ... but no such service exists" in CI?
There are 2 common causes: an interface has no service alias and the class is excluded from autoloading in this env. You type-hinted an interface but never told the container which concrete service implements it, so autowiring has nothing to inject.
How do I fix Symfony "Cannot autowire service ... argument references ... but no such service exists" in CI?
There are 2 fixes depending on which cause you have: alias the interface to a concrete service and bind a scalar or named argument explicitly. Work through them in order, since the first is the most common.
What does Symfony "Cannot autowire service ... argument references ... but no such service exists" in CI actually mean?
Compilation fails with "Cannot autowire service \"X\": argument \"$y\" of method \"__construct()\" references interface \"Z\" but no such service exists." Symfony often suggests aliasing the interface.
How do I stop Symfony "Cannot autowire service ... argument references ... but no such service exists" in CI happening again?
Alias every injectable interface to a concrete implementation. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card