In previous Angular versions (< v18) it was possible to import modules dynamically based on a variable inside of a method, like
initTemplates(moduleName: string): Observable<ScoreboardModule> {
// NOT WORKING ANYMORE
let promise = import(`./layouts/${moduleName}/${moduleName}.module`);
// THIS WORKS
// let promise = import(`./layouts/BER/BER.module`);
return from(promise).pipe(
map(mod => mod.ScoreboardModule),
map((module: any) => {
// do some stuff
return module;
})
);
}
The ng serve
output shows
▲ [WARNING] The glob pattern import("./layouts/**/*/**/*.module") did not match any files [empty-glob]
src/app/mode.competition/components/scoreboard-viewer/scoreboardViewer.abstract.ts:30:29:
30 │ ...t promise = import(`./layouts/${moduleName}/${moduleName}.module`)
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When accessing the code the application breaks with:
Error: Module not found in bundle: ./layouts/BER/BER.module
at chunk-SKK7EFDP.js:26:9
the additional paths are defined in tsconfig.app.json
like this:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"skipLibCheck": true,
"outDir": "./out-tsc/app",
"types": ["node"]
},
"files": ["src/main.ts", "src/polyfills.ts"],
"include": ["src/**/*.d.ts", "src/app/mode.competition/components/scoreboard-viewer/layouts/**/*.ts"]
}
This code was running as described above at least since Angular 13 and breaks suddenly now in Angular 18.
The described issue is part of a real huge software package that cannot be extracted easily. I really hope that the error description is enough to identify the error, without a code example here.
Please does anybody has any ideas, on how to fix it?