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


Angular version: 5.0.5

- [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:


Also see:

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: (@gdi2290 please note) the fix was changing config\build-utils.js @ line 78


const buildOptimizer = prod;


const buildOptimizer = prod && metadata.AOT;

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


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


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: