angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

"ERROR in Error: No NgModule metadata found for 'AppModule'." After Angular 5.2.1 and CLI 1.6.5 update

Open jtsom opened this issue 8 years ago • 43 comments

Versions

Angular CLI: 1.6.5
Node: 9.4.0
OS: darwin x64
Angular: 5.2.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 5.1.0
@angular/cli: 1.6.5
@angular/material: 5.1.0
@ngtools/json-schema: 1.1.0
typescript: 2.5.3
webpack: 3.10.0

Repro steps

  • Update npm packages
  • Update CLI
  • Start app - ng s

Observed behavior

ERROR in Error: No NgModule metadata found for 'AppModule'.
    at NgModuleResolver.resolve (/Users/John/Dev/Javascript/Angular/FRC-TimeTracker/node_modules/@angular/compiler/bundles/compiler.umd.js:20277:23)
    at CompileMetadataResolver.getNgModuleMetadata (/Users/John/Dev/Javascript/Angular/FRC-TimeTracker/node_modules/@angular/compiler/bundles/compiler.umd.js:15230:60)
    at visitLazyRoute (/Users/John/Dev/Javascript/Angular/FRC-TimeTracker/node_modules/@angular/compiler/bundles/compiler.umd.js:31169:104)
    at AotCompiler.listLazyRoutes (/Users/John/Dev/Javascript/Angular/FRC-TimeTracker/node_modules/@angular/compiler/bundles/compiler.umd.js:31137:20)
    at AngularCompilerProgram.listLazyRoutes (/Users/John/Dev/Javascript/Angular/FRC-TimeTracker/node_modules/@angular/compiler-cli/src/transformers/program.js:156:30)
    at Function.NgTools_InternalApi_NG_2.listLazyRoutes (/Users/John/Dev/Javascript/Angular/FRC-TimeTracker/node_modules/@angular/compiler-cli/src/ngtools_api.js:44:36)
    at AngularCompilerPlugin._getLazyRoutesFromNgtools (/Users/John/Dev/Javascript/Angular/FRC-TimeTracker/node_modules/@angular/cli/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:248:66)
    at Promise.resolve.then.then (/Users/John/Dev/Javascript/Angular/FRC-TimeTracker/node_modules/@angular/cli/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:565:50)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)

Desired behavior

App run normally

Mention any other details that might be useful (optional)

Application built and ran just fine before update.

Did try rm -rf node_modules and reinstall, no change.

jtsom avatar Jan 19 '18 13:01 jtsom

I have faced same error. solved it: clean and reinstall global angular-cli and local angular.

keyant avatar Jan 20 '18 07:01 keyant

@keyant can you put steps

hassaniftikhar avatar Jan 20 '18 07:01 hassaniftikhar

steps: cd to project directory

sudo npm uninstall -g @angular/cli
sudo npm cache verify
sudo npm install -g @angular/cli@latest
rm -rf node_modules dist
npm install --save-dev @angular/cli@latest
npm install

sudo npm update -D && sudo npm update -S
sudo npm install typescript@'>=2.4.2 <2.7.0'

keyant avatar Jan 20 '18 07:01 keyant

Tried @keyant 's steps but still got the error No NgModule metadata found for 'AppModule'

vupham2909 avatar Jan 22 '18 04:01 vupham2909

I get this error seemingly random. Can't really see that I've changed anything and suddenly it just stops working and throws that error.

As an example: I had a branch in Visual Studio Team Services that built correctly, and when I re-queued the same build, without any changes, the build didn't work anymore...

ottosson avatar Jan 24 '18 10:01 ottosson

What happens if you upgrade typescript to 2.6.0?

FA-tvonmoll avatar Jan 24 '18 13:01 FA-tvonmoll

Got the same error, in my case it is caused by an import statement: import NgModule = core.NgModule;

For instance following code report error when build.

import core = require("@angular/core"); import NgModule = core.NgModule; @NgModule( {....}) export class AppModule {}

And the error is gone if rewrite the code like below: import core = require("@angular/core"); @core.NgModule( {....}) export class AppModule {}

wuzhen0808 avatar Jan 24 '18 13:01 wuzhen0808

Unbelievable! It works after just editing any ".ts" file.

cli

Albejr avatar Jan 24 '18 15:01 Albejr

Hi @jtsom and @Albejr,

Could you provide a project we can use to reproduce this? A github repo would be great.

hansl avatar Jan 24 '18 19:01 hansl

@Albejr which commit covers this problem?

https://github.com/angular/angular-cli/releases/tag/v1.6.6

  • @angular/cli: add karma-cli as dependency when ejecting (f17c2b3)
  • @angular/cli: allow colon separated schematic name in generate (f9a9d75)
  • @angular/cli: allow for schema-less schematics to be generated (d4dc2e3)
  • @angular/cli: delete node_modules on eject e2e (5c00e1f)
  • @angular/cli: eject now remove all hardcoded paths (53e84fe), closes #9335
  • @angular/cli: exclude nodejs built-ins from process.cwd() resolve (bf87508)
  • @angular/cli: maintain autoprefixer backward compatibility (0f82564)
  • @angular/cli: only force CommonJS if module kind is ES2015 (369f361)
  • @angular/cli: replaced bullet character due to unwanted beeping sounds on windows systems (38db84c)

ottosson avatar Jan 26 '18 07:01 ottosson

Had the same experience earlier as Albejr, but with forEach. TS would fail to compile the code saying something like 'foreach is not a method of '... but if I left the hang compiler stuck, and changed and saved any TS file, the compile on top of the failed one would work.

In other words, I could never run the program on the first compile. I got around it in other ways (sounds like foreach can have unpredictable results, so TS doesn't like it and so I moved to other means). The compiler behaviour made troubleshooting a problem more difficult...

Using cli 1.6.7 I experienced the 'first compile fails' problem too. It was using the CoreUI framework which I'm still new to... before I could really test the problem, it went away. Perhaps a cache issue or something else, but the symptoms were exact as in my earlier case and as Alberjr describes. Something might still not be fully resolved on this front with 1.6.7...

bytech-ca avatar Feb 12 '18 02:02 bytech-ca

@x2361 You are incredible, it works with your workaround.
Even with @angular/cli Version 1.6.6 does not work

captivea-yho avatar Feb 13 '18 10:02 captivea-yho

I still have this problem with angular 5.2.4 and cli 1.6.7. I did npm cache clean --force, rm -rf node modules and package lock, remove webpack from package.json, fresh npm install and build. Still the problem persists.

ghost avatar Feb 13 '18 17:02 ghost

Update typescript of project to 2.6.2 solved it for me.

npm install --save-dev [email protected].

Took sooooo much time to figure out as the solution of deleting cli and cache and reinstalling them was working only partially.

vapits avatar Feb 14 '18 14:02 vapits

@vapits this solved my problem, excellent !

tingtingli911 avatar Feb 15 '18 08:02 tingtingli911

i also faced this error can any one give solution

prasoon-tare avatar Mar 28 '18 06:03 prasoon-tare

OMG i can't believe @Albejr solution worked for me.

hnmmallesh avatar Apr 22 '18 09:04 hnmmallesh

I finally resolved this issue. Resolution below. :-)

Update the Angular CLI version to latest – as of today it’s 1.7.4

How to check the version of @angular/cli

  • ng --version

Go to the folder and type the following commands to update CLI.

  • npm remove @angular/cli
  • npm install —save-dev @angular/cli@latest

Make sure that the Webpack version is 3.11.0 How to check the version of Webpack

  • npm list webpack

How to update webpack

csrssrinivas avatar Apr 23 '18 08:04 csrssrinivas

I have same problem ...

I solved this problem only when remove globaly installed webpack.

npm uninstall -g webpack

achmedzhanov avatar Apr 24 '18 13:04 achmedzhanov

I had the same problem (and the same effect, that the error went away when I edited any .ts file) and the problem was that I imported a module that was already exported via another imported module, like this (where FooSubModule is exported by FooModule):

imports: [
        BrowserModule,
        FooModule,
        FooSubModule
    ],

It's strange in how many different cases this error message appears. More detailed error messages would be highly appreciated.

Liowag avatar Apr 24 '18 15:04 Liowag