Could not find an NgModule. Use the skip-import op

2020-06-07 05:15发布

I get the error in the subject of this post when I use the CLI to create a new component: ng g c my-component --project=my-project (No component is created)

I've seen other posts with the same error message, but none of them also include Nrwl/Nx, which I believe is somehow involved. Project started as Ng4 and was upgraded to Ng6.

Any ideas how I can fix this?

Thx.

TTE

Environment:

  • Angular CLI: 6.0.8
  • Node: 8.9.4
  • OS: win32 x64
  • Angular: 6.0.6
  • @angular-devkit/architect 0.6.8
  • @angular-devkit/build-angular 0.6.8
  • @angular-devkit/build-optimizer 0.6.8
  • @angular-devkit/core 0.6.8
  • @angular-devkit/schematics 0.6.8
  • @angular/cdk 6.3.1
  • @angular/cli 6.0.8
  • @angular/material 6.3.1
  • @ngtools/webpack 6.0.8
  • @schematics/angular 0.6.1
  • @schematics/update 0.6.8
  • rxjs 6.2.1
  • typescript 2.7.2
  • webpack 4.8.3
  • nrwl/nx 6.1.0

UPDATE #1

I tried dropping the --project flag entirely ( so just ng g c my-component) and still get the same problem. Not sure what that means, yet.

标签: angular nrwl
11条回答
我只想做你的唯一
2楼-- · 2020-06-07 05:47
  1. First way:
    I think first you have to go to inside your app folder then type cmd;
    ng g c your_com_name --spec false
    or ng g c your_com_name
    It will definitely create your component or solve your problem.

  2. second way:
    Remove your e2e from your angular.json->projects:
    definitely

    { 
        your_project_name-e2e:{}
    }
    

    example: my-first-app-e2e

    {
          "root": "e2e/",
          "projectType": "application",
          "architect": {
            "e2e": {
              "builder": "@angular-devkit/build-angular:protractor",
              "options": {
                "protractorConfig": "e2e/protractor.conf.js",
                "devServerTarget": "my-first-app:serve"
              }
            },
            "lint": {
              "builder": "@angular-devkit/build-angular:tslint",
              "options": {
                "tsConfig": "e2e/tsconfig.e2e.json",
                "exclude": [
                  "**/node_modules/**"
                ]
              }
            }
          }
        }
    
查看更多
别忘想泡老子
3楼-- · 2020-06-07 05:50

I ended up totally deleting node_modules, clearing out the yarn cache and then running yarn to reinstall all packages. I also edited my angular.json file so that my pathing looked like this for all applications and libraries:

"root": "libs/my-lib",
"sourceRoot": "libs/my-lib/src"

I'm not sure which of those fixed the problem, but all appears to be OK now. At least the immediate problem went away.

Hopefully this helps someone else.

TTE

查看更多
劳资没心,怎么记你
4楼-- · 2020-06-07 05:52

I had the same issue, In angular.json file, I searched for my-project-e2e (replace my-project with your project name) and then I changed:

"root": "" to "root": "e2e" and saved it. Everything was working again.

The solution was specified in this link.

查看更多
冷血范
5楼-- · 2020-06-07 05:55

Quick fix

1) Change current directory in cmd/terminal to src/app

cd src/app (linux)

cd .\src\app\ (windows)

2) Run commands now

ng g c myComponent

查看更多
该账号已被封号
6楼-- · 2020-06-07 06:00

Run component generation command(ng g c component-name) from where the app.module.ts file is located.

查看更多
趁早两清
7楼-- · 2020-06-07 06:01

Had same issue. Turned out to be somehow related to the name of the root component. Renaming back to 'app' resolved the problem

查看更多
登录 后发表回答