Skip to content

Angular5 build-optimizer generates bundles with "Please add a @NgModule annotation." errors #8594

Closed
@Orodan

Description

@Orodan

Versions

Angular CLI: 1.5.0
Node: 8.1.3
OS: linux x64
Angular: 5.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.5.0
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.36
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.5
typescript: 2.4.2
webpack: 3.8.1

Repro steps

  • ng build --prod --aot false
    Or :
  • ng serve --prod --aot false

Observed behavior

The app served with "ng serve --prod --aot false" gives the following error in the browser console :

"Unexpected value 'e' imported by the module 'e'. Please add a @NgModule annotation."

Desired behavior

I expected no error as a simple ng serve serves the app with no error.

Mention any other details that might be useful (optional)

At first I encounter this problem after migrating from angular 4 to 5 and building my app with

ng build --prod --aot false

After deploying on a web server, I ended up with the error previously mentionned.
I've done some digging, and I found out that it was the fault of the build-optimizer added with angular 5 (it is activated by default with the --prod flag) because if I deactivate it with the following command line, it works fine :

ng build --prod --aot false --build-optimizer false

I've run some more tests, and I also found out that serving the app this way gives me the same error on my browser console :

ng serve --prod --aot false

My best guess for now is that the build-optimizer only works with aot, because if when I tried the following command :

ng serve --build-optimizer true

It tells me that I need the aot flag

The `--build-optimizer` option cannot be used without `--aot`.

Hope you can help,
Thanks

Metadata

Metadata

Assignees

Labels

needs: repro stepsWe cannot reproduce the issue with the information given

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions