Angular2 - Could not find an NgModule

前端 未结 6 1342
难免孤独
难免孤独 2020-12-07 05:44

Hello I\'ve just created a new project from the CLI using the simple

ng new frontend

command however once I go into my project to:

相关标签:
6条回答
  • 2020-12-07 06:02

    Using Angular@7 ng g c works from the root app folder. No need to change anything - just run from the base directory something like ng g c features/shopping-list/components/shopping-list-edit => CREATE src/app/features/shopping-list/components/shopping-list-edit/shopping-list-edit.component.ts (316 bytes)

    0 讨论(0)
  • 2020-12-07 06:03

    Change root to the directory where your module is in angular.json

    From:

    root:""
    

    to directory of app module:

    root: "/src/app"
    
    0 讨论(0)
  • 2020-12-07 06:08

    Could not find ngModule can be solved by passing --module=<path to app.module.ts>

    There are multiple ways to fix this issue one among them is as follows,

    ng g c components/list-template --module=modules/app.module.ts
    

    For other options with respect to generate component is here https://angular.io/cli/generate#component

    0 讨论(0)
  • 2020-12-07 06:10

    The code for generating a component and resolving closest NgModule is quite straightforward. You can find it here https://github.com/angular/devkit/blob/master/packages/schematics/angular/component/index.ts [Note: link currently dead 15 June 2020]

    It doesn't depend on the typescript, npm etc. version. Only on the @angular/cli version (and indirectly on the devkit) which in your case is the latest. All should be working fine; at least it does on my end.

    0 讨论(0)
  • 2020-12-07 06:18

    you should run this command 'ng g c component-name' inside is app folder.

    1) cd src/app 2) ng g c component name

    0 讨论(0)
  • 2020-12-07 06:26

    In my case, the problem was in angular.json file. I had to remove all the 'projectname-e2e' project at the angular.json file for fix this issue.

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