October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Angular NG0204: Invalid Injection Token — Causes and Fixes

Angular NG0204 means a dependency could not be resolved during class construction. Trace the failing constructor parameter, confirm its runtime token and provider, and verify both sides use the same token instance.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular NG0204 means Angular could not resolve a dependency while constructing a class. Start with the class and constructor parameter named in the error, then check its injectable metadata, whether the parameter has a runtime token, whether that token is provided in the consumer’s scope, and whether both sides use the same token instance.

What NG0204 means

Angular’s official error title is “Invalid Injection Token.” The error occurs when Angular cannot resolve a dependency for a class during dependency injection. Common causes include a class with dependencies that lacks @Injectable(), an unresolvable constructor parameter, or an InjectionToken without a suitable provider definition. See Angular’s NG0204 error reference.

As an Amazon Associate I earn from qualifying purchases.

The wording helps narrow the problem. In Can't resolve all parameters for X: (?, ?, ?), each question mark indicates a constructor parameter Angular could not resolve. If the message says Token X is missing a ɵprov definition, the token lacks a provider definition; register a provider or give the token a suitable factory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to diagnose NG0204

  1. Identify the failing class and parameter

    Read the full error and stack trace. Find the class Angular was constructing, then map each question mark in the “Can’t resolve all parameters” message to the constructor’s arguments in order. Begin with the marked parameter rather than changing unrelated providers.

  2. Check injectable metadata

    If Angular is expected to construct a class that has constructor dependencies, ensure it has the appropriate @Injectable() metadata. Angular’s error example demonstrates adding the decorator. Also check that the class being instantiated is the one with the metadata, rather than a similarly named class or an unintended import.

  3. Confirm the dependency has a runtime token

    Angular needs a runtime value to identify a dependency. TypeScript interfaces and other type-only forms disappear after compilation, so they cannot serve as injection tokens. For interface-shaped configuration, functions, arrays, or parameterized types, define an InjectionToken. Angular describes these cases in its InjectionToken API documentation.

  4. Check provider registration and scope

    A valid token still needs a provider available to the consumer, unless it has a suitable factory or is otherwise automatically provided. Angular supports automatic provision through @Injectable metadata or a token factory, as well as manual provider arrays. See the dependency provider guide.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

    Choose a provider strategy based on what the dependency represents: useClass constructs an implementation, useValue supplies a fixed value, useFactory creates a value, and useExisting aliases another provider. Confirm the registration is in a scope visible to the code requesting the dependency.

  5. Verify token identity

    An InjectionToken description is for debugging; Angular identifies the token by its object reference. The provider and consumer must use the same exported token instance. Creating two tokens with identical descriptions does not make them interchangeable. Define the token once in a shared module or file, then import that token at both the provider and injection sites. Angular documents token identity in the InjectionToken API and DI debugging guide.

A safe pattern for interface-shaped dependencies

Use one shared token for the interface-shaped value, provide it, and inject that same token. The generic type helps TypeScript check usage; the token object supplies the runtime identity Angular needs.

import { InjectionToken, inject } from '@angular/core';

export interface AppConfig {
  apiBaseUrl: string;
}

export const APP_CONFIG = new InjectionToken<AppConfig>('app.config');

// In an appropriate provider scope:
{ provide: APP_CONFIG, useValue: { apiBaseUrl: '/api' } }

// In a class or another supported injection context:
const config = inject(APP_CONFIG);

Adapt the provider strategy and scope to the application. A token factory is another option when the value can be created by the token’s factory configuration; it is not a substitute for using the same token object at both ends.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why common quick fixes may not work

  • Adding @Optional() does not create a runtime token. It can make a valid dependency optional when no provider is found, but it cannot turn an interface into a runtime token or make two distinct InjectionToken objects identical.
  • Matching token descriptions is not enough. Re-create neither the provider token nor the injection token independently; import the one shared instance.
  • Adding a provider in the wrong scope may not help. The provider must be visible to the consumer requesting the dependency.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make sure the error is really NG0204

Nearby Angular DI errors point to different failure layers, so use the code actually reported before changing provider setup.

Error What it indicates Where to look
NG0204 Angular cannot resolve a dependency for a class. Class metadata, constructor token, provider registration and scope, or token identity. Angular error reference.
NG0203 inject() was called outside an injection context. Move the call to a supported context, such as construction, field initialization, or a provider or token factory. A later lifecycle hook is outside the supported context. Angular error reference and inject API documentation.
NG2003 Angular has no runtime token for a constructor parameter, often because the parameter uses a primitive type. Provide a runtime token, commonly an InjectionToken, and configure its provider as needed. Angular error reference.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.