Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap: Angular production mode cannot be enabled due to AbstractStarkMain implementation #506

Closed
christophercr opened this issue Jul 13, 2018 · 0 comments · Fixed by #508

Comments

@christophercr
Copy link
Collaborator

christophercr commented Jul 13, 2018

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/NationalBankBelgium/stark/blob/master/CONTRIBUTING.md#got-a-question-or-problem

Current behavior

When running the production build of an app that uses the bootstrap main class from stark-core implemented in #486 , Angular fails to enable the "production mode":

Error: Cannot enable prod mode after platform setup.
    at An (application_ref.ts:48)
    at decorateModule (abstract-stark-main.ts:140)
    at e.invoke (zone.js.pre-build-optimizer.js:388)
    at t.run (zone.js.pre-build-optimizer.js:138)
    at zone.js.pre-build-optimizer.js:872
    at e.invokeTask (zone.js.pre-build-optimizer.js:421)
    at t.runTask (zone.js.pre-build-optimizer.js:188)
    at m (zone.js.pre-build-optimizer.js:595)
    at t.invokeTask [as invoke] (zone.js.pre-build-optimizer.js:500)
    at _ (zone.js.pre-build-optimizer.js:1540)

Expected behavior

The Angular production mode should be correctly enabled in the production build of the application.

Minimal reproduction of the problem with instructions

Use the bootstrap logic provided by stark-core in your main.browser.ts like this:

class Main extends AbstractStarkMain {
	public constructor(env: StarkEnvironment) {
		super(env);
	}

	public main = (): Promise<any> => {
		console.log("Bootstrapping the App");

		// Bootstrap our Angular app with a top level NgModule
		return (
			platformBrowserDynamic()
				.bootstrapModule(AppModule)
				// the line below adapts the module depending on the environment
				// if you don't like what stark does by default, you can instead do your own customizations through the environment.* files
				// and use environment.customizeAppModule instead
				.then(this.decorateModule)
		);
	};
}

new Main(environment).bootstrap();

Create the production build of the app and serve the application by running these commands

  • npm run build:prod
  • npm run server:prod

Open the app in the browser and check the console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant