Solvedangular Angular 5 Error: Unexpected value 't' imported by the module 't'. Please add a @NgModule annotation

When I run 'ng serve', my app work well.
But when I run 'ng build' and test by run 'http-server dist/ -o' my app not running with error:
screenshot from 2017-12-06 14-50-26

I'm submitting a...

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

Environment

Angular version: 5.0.5


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 8.9.1  
- Platform: Linux 

Others: HTTP server
25 Answers

✔️Accepted Answer

Just in case anyone else is having this same issue I managed to work around this issue with the help of this Angular bug fix:

angular/angular-cli#8594

Also see:

https://github.com/angular/angular-cli/pull/8346/files/f0f81be1acb871b7eb623b45354b09728839c3ee

The fix is to not use the buildOptimizer for JIT in production builds.

For my project specifically because it is based on the angular starter repo here: https://github.com/gdi2290/angular-starter (@gdi2290 please note) the fix was changing config\build-utils.js @ line 78

From:

const buildOptimizer = prod;

To:

const buildOptimizer = prod && metadata.AOT;

And just to be tidy I removed the now redundant AOT check @ line 109

From:

use: metadata.AOT && buildOptimizer ? [ buildOptimizerLoader, '@ngtools/webpack' ] : [ '@ngtools/webpack' ]

To:

use: buildOptimizer ? [ buildOptimizerLoader, '@ngtools/webpack' ] : [ '@ngtools/webpack' ]

Anyway hope this helps because I have wasted a lot of time on this.

Other Answers:

I have the same issue. Can anyone post a fix pls?

More Issues: