Angular 2 : No NgModule metadata found

后端 未结 28 1260
盖世英雄少女心
盖世英雄少女心 2020-11-30 05:31

I\'m brand new to Angular 2 and attempting to follow along with a video tutorial I found. Despite following all of the steps, Angular just won\'t work; I get the following e

相关标签:
28条回答
  • 2020-11-30 05:59

    With Angular 5, I solved a similar problem by ugrading to @angular/cli 1.6.1 from 1.5.5:

    "devDependencies": {
      "@angular/cli": "1.6.1"
    }
    

    During ng serve the error I got was:

    ERROR in Error: No NgModule metadata found for 'AppModule'.
        at NgModuleResolver.resolve (/path/to/project/app/node_modules/@angular/compiler/bundles/compiler.umd.js:20247:23)
    
    0 讨论(0)
  • 2020-11-30 06:00

    I had the same problem and couldn't solve it after reading all the above answers. Then I noticed that an extra comma in declarations was creating a problem. Removed it, problem solved.

    @NgModule({
        imports: [
            PagesRoutingModule,
            ThemeModule,
            DashboardModule,
        ],
        declarations: [
            ...PAGES_COMPONENTS,
            **,**
        ],
    })
    
    0 讨论(0)
  • 2020-11-30 06:00

    I finally found the solution.

    1. Remove webpack by using following command.
    npm remove webpack
    
    1. Install cli by using following command.
    npm install --save-dev @angular/cli@latest
    

    after successfully test app, it will work :)

    If not then follow below steps:

    1. Delete node_module folder.
    2. Clear cache by using following command.
    npm cache clean --force
    
    1. Install node packages by using following command.
    npm install
    
    1. Install angular@cli by using following command.
    npm install --save-dev @angular/cli@latest
    

    Note: If failed, try step 4 again. It will work.

    0 讨论(0)
  • 2020-11-30 06:02

    I'll give you few suggestions.Remove all these as mentioned below

    1)<script src="polyfills.bundle.js"></script>(index.html)  //<<<===not sure as Angular2.0 final version doesn't require this.
    
    2)platform.bootstrapModule(App); (main.ts)
    
    3)import { NgModule } from '@angular/core'; (app.ts)
    
    0 讨论(0)
  • 2020-11-30 06:04

    In my case, I had defined a couple of (private) static methods in one of my components and was using them in the same component.

    0 讨论(0)
  • 2020-11-30 06:07

    I had the same issue and I resolved it by closing the editor i.e. Visual Studio Code, started it again, run ng serve and it worked.

    0 讨论(0)
提交回复
热议问题