Angular 2 Component is not part of any NgModule

前端 未结 9 2091
予麋鹿
予麋鹿 2020-12-08 18:12

i\'m upgrading my Angular 2 project from RC5 to 2.0.0. I get this Error

Unhandled Promise rejection: Component LoginComponent is not part of any NgM

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 18:49

    I had the same error. I had a lot of components and had missed some out in app.module.ts but I was not sure which ones.

    I found out by adding a log statement to ..

    /node_modules/@angular/compiler/bundles/compiler.umd.js

    // I ADDED THIS LOG STATEMENT
    console.log('compType', String(compType));
    // THIS LINE EXISTS ALREADY
    throw new Error("Component " + stringify(compType) + " is not part of any NgModule or the module has not been imported into your module.");
    

    The log statement shows you which component you forgot to add to app.module.ts .. just click the output of the log statement in the browser console tab for details.

    Remove the log statement when you are done.

    NOTE: Make sure you are using compiler.umd.js (NOT compiler.umd.min.js) in your SystemJS config file.

提交回复
热议问题