angular/angular · error · RuntimeError

DUPLICATE_NG_MODULE_ID

DUPLICATE_NG_MODULE_ID

Error message

Duplicate module registered for ${id} - ${stringify(type)} vs ${stringify(type.name)}

What it means

Error "Duplicate module registered for ${id} - ${stringify(type)} vs ${stringify(type.name)}" thrown in angular/angular.

Source

Thrown at packages/core/src/linker/ng_module_registration.ts:28

import {Type} from '../interface/type';
import {NgModuleType} from '../metadata/ng_module_def';
import {stringify} from '../util/stringify';

/**
 * Map of module-id to the corresponding NgModule.
 */
const modules = new Map<string, NgModuleType>();

/**
 * Whether to check for duplicate NgModule registrations.
 *
 * This can be disabled for testing.
 */
let checkForDuplicateNgModules = true;

function assertSameOrNotExisting(id: string, type: Type<any> | null, incoming: Type<any>): void {
  if (type && type !== incoming && checkForDuplicateNgModules) {
    throw new RuntimeError(
      RuntimeErrorCode.DUPLICATE_NG_MODULE_ID,
      ngDevMode &&
        `Duplicate module registered for ${id} - ${stringify(type)} vs ${stringify(type.name)}`,
    );
  }
}

/**
 * Adds the given NgModule type to Angular's NgModule registry.
 *
 * This is generated as a side-effect of NgModule compilation. Note that the `id` is passed in
 * explicitly and not read from the NgModule definition. This is for two reasons: it avoids a
 * megamorphic read, and in JIT there's a chicken-and-egg problem where the NgModule may not be
 * fully resolved when it's registered.
 *
 * @codeGenApi
 */
export function registerNgModuleType(ngModuleType: Type<any>, id: string): void {

View on GitHub (pinned to 51cb07e980)

Solutions

  1. Remove the duplicate module registration; ensure each NgModule id is registered once.

When it happens

Trigger: Thrown at packages/core/src/linker/ng_module_registration.ts:28 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of angular/angular@51cb07e980 (2026-08-22). Data as JSON: /api/errors/7d5ccbf0ca3fd2e8. Report an issue: GitHub.