Could not find an NgModule. Use the skip-import option to skip importing in NgModule

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


The generate of components aims to do 2 things:

  • create source code for the component
  • registers the component in a module (by default, in the app.module.ts)

The problem is, that you don't have an app.module.ts. You renamed it to something else, or perhaps even have multiple of them. In that case there are 2 possible solutions:

  1. you do the registration of the component manually. (easiest)

    ng g component mycomponent --skip-import

  2. you specify the module with the -m switch. (might be broken) There is a long thread about it here: https://github.com/nrwl/nx/issues/526


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

Tags:

Angular

Nrwl