question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mauriziovitalecommented, Dec 6, 2017

I’m having the same problem. This is the repository @filipesilva angualar-build-optimizer-true you can run: npm install && npm run build:fail && npm run start:fail

package.json
{ 
"start:fail": "ng serve --prod --aot=false --build-optimizer=true ",
"build:fail": "ng build --prod --aot=false --build-optimizer=true "
}
angualar build optimizer true error

It works fine when you run (in this case the --aot is enabled) npm install && npm run build && npm run start

package.json
{ 
"start": "ng serve --prod --build-optimizer=true ",
"build": "ng build --prod --build-optimizer=true "
}
angualar-build-optimizer-true
0reactions
angular-automatic-lock-bot[bot]commented, Sep 8, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Please add a @NgModule annotation" Error on Angular2
If you are using Angular 5.0 you need to add "annotationsAs": "decorators" to the "angularCompilerOptions" for your package.
Read more >
NgModules - Angular
@NgModule takes a metadata object that describes how to compile a component's template and how to create an injector at runtime. It identifies...
Read more >
unexpected value 'chooser' imported by the module ... - You.com
Try this: import {HttpClientModule} from '@angular/common/http';. Open side panel. Unexpected value imported by the module please add a @ngmodule annotation.
Read more >
Error message Is it missing @NgModule annotation? NG6002
https://codedocu.com/Net-Framework/ASP_dot_Net-Core/ Angular / Errors / Angular -Error_colon_-Is-it-missing-an-@ NgModule - annotation ?2672Error ...
Read more >
@angular-devkit/build-optimizer | Yarn - Package Manager
update locale setting snippet to use globalThis . @angular-devkit/schematics. Commit, Type, Description. 207358afb, feat, add runSchematic and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found