Closed
Description
Versions
Angular CLI: 1.5.4 (e)
Node: 6.11.3
OS: darwin x64
Angular: 5.1.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.5.4
@angular-devkit/build-optimizer: 0.0.35
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.41
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.4
@schematics/angular: 0.1.10
@schematics/schematics: 0.0.10
typescript: 2.4.2
webpack-concat-plugin: 1.4.0
webpack-dev-server: 2.9.7
webpack: 3.8.1
Repro steps
- Create a new project with: ng new project-name
- Run using: ng serve --prod
- Open browser and it runs as expected
- Change main.ts to split the call to platformBrowserDynamic() from the call to bootstrapModule()
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule)
.catch(err => console.log(err));
- Run: ng serve --prod
- Open browser and see error in console:
Error: No NgModule metadata found for 'function (){}'.
Observed behavior
Complete stack trace:
main.9d791305398abba6bf45.bundle.js:1 Uncaught Error: No NgModule metadata found for 'function (){}'.
at e.resolve (main.9d791305398abba6bf45.bundle.js:1)
at e.getNgModuleMetadata (main.9d791305398abba6bf45.bundle.js:1)
at e._loadModules (main.9d791305398abba6bf45.bundle.js:1)
at e._compileModuleAndComponents (main.9d791305398abba6bf45.bundle.js:1)
at e.compileModuleAsync (main.9d791305398abba6bf45.bundle.js:1)
at e.compileModuleAsync (main.9d791305398abba6bf45.bundle.js:1)
at e.LMZF.e.bootstrapModule (main.9d791305398abba6bf45.bundle.js:1)
at Object.cDNt (main.9d791305398abba6bf45.bundle.js:1)
at n (inline.687454df27f852918dab.bundle.js:1)
at Object.0 (main.9d791305398abba6bf45.bundle.js:1)
Desired behavior
It should work identically as when the calls are chained.
Mention any other details that might be useful (optional)
The reason for making this change to split into two lines is that in my case, in the handler for the promise returned from bootstrapModule() I need to do some initialization and I need access to the platfor. Calling platformBrowserDynamic() seems to return a different platform if you call it a second time so I need the one used to call bootstrapModule on:
// this is unique to my portal environment
declare var wrapper: any;
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule)
.then((ref: NgModuleRef<AppModule>) => {
// setup required for my portal environment
wrapper.setApplicationComponentNode(ref, platform);
})
.catch(err => console.log(err));
The only workaround at the moment for this is to create a separate main-prod.ts file, eject the webpack config and then modify it to use a different main file for prod vs. dev build.