akveo/ngx-admin · error
${moduleName} has already been loaded. Import Core modules i
Error message
${moduleName} has already been loaded. Import Core modules in the AppModule only. What it means
Error "${moduleName} has already been loaded. Import Core modules in the AppModule only." thrown in akveo/ngx-admin.
Source
Thrown at src/app/@core/module-import-guard.ts:3
export function throwIfAlreadyLoaded(parentModule: any, moduleName: string) {
if (parentModule) {
throw new Error(`${moduleName} has already been loaded. Import Core modules in the AppModule only.`);
}
}
View on GitHub (pinned to dc6a442704)
Solutions
- Ensure CoreModule is imported only once, in AppModule (app.module.ts). Remove any CoreModule imports from lazy-loaded feature modules, SharedModule, or other modules.
- Check that all imports of CoreModule in the codebase are removed except the single import in AppModule (e.g. grep for 'CoreModule' across src/app).
- If CoreModule is imported in a module that is itself imported by AppModule twice (directly and transitively), break that cycle so it is loaded exactly once.
- Verify the guard call: CoreModule's constructor should call throwIfAlreadyLoaded(parentModule, 'CoreModule') and AppModule must pass itself as parentModule; if parentModule is incorrectly truthy for a legitimate single load, fix the constructor signature/usage.
- If CoreModule was intentionally imported twice (e.g. in tests), restructure so a single forRoot-style provider pattern is used instead of importing the whole module twice.
Defensive patterns
Strategy: validation
Validate before calling
// In any module other than AppModule, do not import CoreModule.
// Pre-check you can run before building/committing:
// grep -rn "CoreModule" src/app --include='*.ts' | grep -v 'core.module.ts'
// Ensure CoreModule appears only in app.module.ts imports.
import { CoreModule } from './@core/core.module';
function coreModuleImports(): string[] {
// conceptual: verify only AppModule imports it
return ['app.module.ts'];
} Type guard
// The guard itself is a runtime check; a defensive wrapper:
export function ensureImportedInRootOnly(parentModule: unknown, moduleName: string): void {
if (parentModule) {
throw new Error(`${moduleName} has already been loaded. Import Core modules in the AppModule only.`);
}
} Try / catch
// Usually thrown during bootstrap (ngModule constructor) and not catchable in app code;
// catch is only useful in programmatic bootstrap scenarios:
try {
platformBrowserDynamic().bootstrapModule(AppModule);
} catch (err) {
if (err instanceof Error && err.message.includes('has already been loaded')) {
console.error('CoreModule imported more than once: remove it from all modules except AppModule.');
} else {
throw err;
}
} Prevention
- Import CoreModule only in AppModule; use SharedModule for reusable components/directives/pipes.
- Provide singleton services via `@Injectable({ providedIn: 'root' })` so feature modules never need CoreModule.
- Adopt a forRoot()/forChild() pattern for modules that must be configured once.
- Run a lint/grep check in CI asserting CoreModule is imported only in app.module.ts.
- Read the guard error's stack trace — it points to the second importing module.
When it happens
Trigger: Thrown at src/app/@core/module-import-guard.ts:3 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of akveo/ngx-admin@dc6a442704 (2026-08-30).
Data as JSON: /api/errors/d17f520a39833dc7.
Report an issue: GitHub.