Getting "No NgModule metadata found for 'class{}'." with custom bootstrap in AOT build

1,021 views
Skip to first unread message

CSchulz

unread,
Feb 7, 2020, 6:06:14 AM2/7/20
to Angular and AngularJS discussion
Hello,

I am struggling with custom bootstrap code and AOT.
We have a custom bootstrap function which is called in the main.ts


When I run it with JIT everything works fine in the browser.
Running it with AOT I get following error:

Uncaught Error: No NgModule metadata found for 'class{}'.
    at NgModuleResolver.resolve (rs/webpack:/abc/node_modules/@angular/compiler/fesm2015/compiler.js:20900)
    at CompileMetadataResolver.getNgModuleMetadata (rs/webpack:/abc/node_modules/@angular/compiler/fesm2015/compiler.js:20029)
    at JitCompiler._loadModules (rs/webpack:/abc/node_modules/@angular/compiler/fesm2015/compiler.js:25824)
    at JitCompiler._compileModuleAndComponents (rs/webpack:/abc/node_modules/@angular/compiler/fesm2015/compiler.js:25807)
    at JitCompiler.compileModuleAsync (rs/webpack:/abc/node_modules/@angular/compiler/fesm2015/compiler.js:25769)
    at useClass.compileModuleAsync (rs/webpack:/abc/node_modules/@angular/platform-browser-dynamic/fesm2015/platform-browser-dynamic.js:223)
    at compileNgModuleFactory (rs/webpack:/abc/node_modules/@angular/core/fesm2015/core.js:40264)
    at PlatformRef.bootstrapModule (rs/webpack:/abc/node_modules/@angular/core/fesm2015/core.js:40599)
    at bootstrapFn (rs/webpack:/abc/dist/commons/fesm2015/huk-apps-commons.js:2485)
    at SafeSubscriber._next (rs/webpack:/abc/dist/commons/fesm2015/huk-apps-commons.js:2517)

I have tried to debug the issue and it seems that my AppModule is called class anonymous and has no annotations anymore.

Any ideas?


Best Regards

CSchulz

unread,
Feb 7, 2020, 7:17:16 AM2/7/20
to Angular and AngularJS discussion
I have tracked down the issue to the "Replace Bootstrap Transformer" https://github.com/angular/angular-cli/blob/f85c00ad5577e5f417aa7741c20c84ce1174c42f/packages/ngtools/webpack/src/transformers/replace_bootstrap.ts.

It seems that it is trying to find the bootstrapModule and platformBrowserDynamic functions within the entry module where the module class is defined.

Is there no possibility to extract duplicated bootstrap code?
Reply all
Reply to author
Forward
0 new messages