{"record":{"id":"d17f520a39833dc7","repo":"akveo/ngx-admin","slug":"modulename-has-already-been-loaded-import-core","errorCode":null,"errorMessage":"${moduleName} has already been loaded. Import Core modules in the AppModule only.","messagePattern":"(.+?) has already been loaded\\. Import Core modules in the AppModule only\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/app/@core/module-import-guard.ts","lineNumber":3,"sourceCode":"export function throwIfAlreadyLoaded(parentModule: any, moduleName: string) {\n  if (parentModule) {\n    throw new Error(`${moduleName} has already been loaded. Import Core modules in the AppModule only.`);\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":6,"githubUrl":"https://github.com/akveo/ngx-admin/blob/dc6a442704bfef34b776b5eb15faf852d9e2f75c/src/app/@core/module-import-guard.ts#L1-L6","documentation":"Error \"${moduleName} has already been loaded. Import Core modules in the AppModule only.\" thrown in akveo/ngx-admin.","triggerScenarios":"Thrown at src/app/@core/module-import-guard.ts:3 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// In any module other than AppModule, do not import CoreModule.\n// Pre-check you can run before building/committing:\n// grep -rn \"CoreModule\" src/app --include='*.ts' | grep -v 'core.module.ts'\n// Ensure CoreModule appears only in app.module.ts imports.\nimport { CoreModule } from './@core/core.module';\n\nfunction coreModuleImports(): string[] {\n  // conceptual: verify only AppModule imports it\n  return ['app.module.ts'];\n}","typeGuard":"// The guard itself is a runtime check; a defensive wrapper:\nexport function ensureImportedInRootOnly(parentModule: unknown, moduleName: string): void {\n  if (parentModule) {\n    throw new Error(`${moduleName} has already been loaded. Import Core modules in the AppModule only.`);\n  }\n}","tryCatchPattern":"// Usually thrown during bootstrap (ngModule constructor) and not catchable in app code;\n// catch is only useful in programmatic bootstrap scenarios:\ntry {\n  platformBrowserDynamic().bootstrapModule(AppModule);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('has already been loaded')) {\n    console.error('CoreModule imported more than once: remove it from all modules except AppModule.');\n  } else {\n    throw err;\n  }\n}","preventionTips":["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."],"tags":[],"backgroundTag":null,"analyzedSha":"dc6a442704bfef34b776b5eb15faf852d9e2f75c","analyzedAt":"2026-08-30T19:25:49.753Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}