Invalid Injection Token
This error occurs when Angular cannot resolve a dependency for a class during dependency injection. This most commonly affects classes using constructor injection, where Angular relies on TypeScript metadata to determine parameter types.
The most common causes are:
- A service class is missing the
@Service()or the@Injectabledecorator - An
InjectionTokenlacks a proper provider definition - A constructor parameter cannot be resolved
NOTE
The inject() function takes an explicit token, so the "unresolvable parameter" scenario does not apply to it directly. However, if the injected class itself is missing @Service() and has its own constructor dependencies, the error can still occur.
Common scenarios
Missing @Service() decorator
When a class has constructor dependencies but lacks the @Service() decorator, Angular cannot resolve its parameters:
export class UserClient {
constructor(private http: HttpClient) {} // Angular can't resolve this
}Add the @Service() decorator to fix this:
@Service()
export class UserClient {
constructor(private http: HttpClient) {}
}Unresolvable constructor parameters
This error also appears when Angular cannot determine the type of a constructor parameter:
@Service()
export class DataStore {
// Angular can't resolve 'config' without a provider
constructor(private config: AppConfig) {}
}Ensure all constructor parameters either have providers configured or use @Optional() for optional dependencies.
Debugging the error
The error message includes details about which token could not be resolved:
Can't resolve all parameters for X: (?, ?, ?)— The?marks indicate unresolvable parameters. Check that the class has@Serviceor@Injectable()and all dependencies have providers.Token X is missing a ɵprov definition— AnInjectionTokenwas used without configuring a provider. Register the token with a value using{provide: TOKEN, useValue: ...}or add a default factory to the token definition.
Work backwards from the error's stack trace to identify where the problematic injection occurs, then verify that:
- The class has a
@Serviceor@Injectable()decorator - All constructor parameters have registered providers
- Any
InjectionTokenhas a configured provider or default value