Skip to content

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:

  1. A service class is missing the @Service() or the @Injectable decorator
  2. An InjectionToken lacks a proper provider definition
  3. 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:

ts
export class UserClient {
  constructor(private http: HttpClient) {} // Angular can't resolve this
}

Add the @Service() decorator to fix this:

ts
@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:

ts
@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 @Service or @Injectable() and all dependencies have providers.
  • Token X is missing a ɵprov definition — An InjectionToken was 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:

  1. The class has a @Service or @Injectable() decorator
  2. All constructor parameters have registered providers
  3. Any InjectionToken has a configured provider or default value

Released under the MIT License.