0

I am working on Angular 6 application and trying to use CLI to create new component using 'ng g c myComponent' but getting error

My all components are under module folder of app / (root level component)

error

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

warning message

 Your global Angular CLI version (7.2.2) is greater than your local
 version (6.2.9). The local Angular CLI version is used.

 To disable this warning use "ng config -g cli.warnings.versionMismatch 
 false".
 Two or more projects are using identical roots. Unable to determine 
 project using current working directory. Using default workspace project 
 instead.

when I run ng --version, I get following app versions

Angular CLI: 6.2.9
Node: 8.9.3
OS: win32 x64
Angular: 5.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@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.8.9
@angular/cli                      6.2.9
@ngtools/webpack                  6.0.8
@schematics/angular               0.8.9
@schematics/update                0.8.9
rxjs                              5.5.12
typescript                        2.5.3
webpack                           4.8.3
K.Z
  • 5,201
  • 25
  • 104
  • 240
  • Possible duplicate of [Could not find an NgModule. Use the skip-import option to skip importing in NgModule](https://stackoverflow.com/questions/51200919/could-not-find-an-ngmodule-use-the-skip-import-option-to-skip-importing-in-ngmo) – Gonzalo Lorieto Jan 25 '19 at 12:50
  • I suppose you may just run this command in wrong path. Are you completely sure, that you're running this command in the folder where components suppose to be? – andrey.shedko Jan 25 '19 at 12:52
  • i refer this blog but i not reaching to any solution – K.Z Jan 25 '19 at 12:53
  • 1
    i believe i am in correct folder C:\Developments\Dev\MyAngularProject\src\app\modules> ng g c MyComponent – K.Z Jan 25 '19 at 12:55
  • Gonzalo Lorieto, I did not got solution... – K.Z Jan 25 '19 at 13:14
  • Call `ng g c MyComponent` from the same directory where the package.json is located. – pzaenger Jan 25 '19 at 13:17
  • I call ng g c MyComponent from the same directory where the package.json is located same error .... – K.Z Jan 25 '19 at 14:41

3 Answers3

0

Make sure your app module is in the folder where you are generating the component. This solved it for me.

0

I encountered the same issue when I was creating a component within a specific feature (or project). And I realized I had to get into the app directory.

Jade
  • 40
  • 7
0

Run cmd:

ng g c <name> --skip-import

Add the --skip-import option.
Reason: It will skip new component entry in the module.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31