Solvedangular Angular 6 upgrade: ERROR in No NgModule metadata found for 'AppModule'

I'm submitting a...

[x] Bug report  

Current behavior

We upgraded our Angular 5 apps to Angular 6. While building works fine for all Linux and macOS users, our Windows users run into

ERROR in No NgModule metadata found for 'AppModule'

when running ng build. However, ng build --aot works fine.

Expected behavior

ng build should work even without --aot on all platforms.

Minimal reproduction of the problem with instructions

Unfortunately, I cannot produce a repository that reproduces the issue. I realize that this is less than ideal, but I'm happy to debug our app if there are any ideas as to what to look into. Sadly, running ng build --verboseonly shows the same error twice instead of once.

What is the motivation / use case for changing the behavior?

We want to build our app :-)

Environment

Angular version: 6.0.3

Browser:
- [x] All browsers (or none, since the build is failing)
 
For Tooling issues:
- Node version: 9.11.1
- Platform:  Windows (Linux & macOS work!)

Others:

  • This happens only for Windows users as far as we can tell for now.
  • Related: angular/angular-cli#10516, but opening here since the error message comes from angular itself, not from the CLI.
  • I looked through existing issues but couldn't find anything helpful and certainly nothing mentioning the specificness to Windows.
35 Answers

✔️Accepted Answer

This error is displayed when there's a template compilation error or a node_module library issue, but somehow the angular-cli process can't caught it and display it, so in order to see what is going on just run the ng build --prod command and it will display whatever error you have.

After fixing the errors you won't see that message again.

Other Answers:

@michahell The link in your answer contains the solution indeed (for me). Maybe it is good to mention that the answer that did it for me was by https://stackoverflow.com/users/516708/bahri-gungor and not the selected answer.
I quote his answer her:

After upgrading to Angular 6, I encountered the "ERROR in No NgModule metadata found for 'AppModule'." with the angular-bootstrap-md package, which requires a tsconfig.json "include" as follows:

"include": ["node_modules/angular-bootstrap-md//*.ts", "src//*.ts"],

After days of troubleshooting and hair pulling, the solution was to arrange the list so that the app.module.ts was located first, under "src/**/*.ts". An Angular bug, perhaps?

"include": ["src//*.ts","node_modules/angular-bootstrap-md//*.ts" ],

I genuinely hope this helps somebody, as I tried everything in this posting and nothing helped. After this change, everything compiles and works beautifully, as expected.

degrootsde answer solved my issue as well. I have no idea why rearranging
"include": ["src//.ts","node_modules/angular-bootstrap-md//.ts" ], solved the problem. But am happy I didn't need to debug it too long. Other way I found of solving this was to add a blank line to app.module.ts and save the file while ng serve was running, this seemed to be temporary an next time I started ng serve I would have to do the same again. It all seems a little strange . I am also an angular-bootstrap-md and windows user running in vscode.

More Issues: