When your project directory is in a another directory, accessed through a symlink, ng generate component some-component
can't find any NgModule.
Angular CLI: 6.0.0
Node: 8.11.1
OS: linux x64
Angular: 6.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.0
@angular-devkit/build-angular 0.6.0
@angular-devkit/build-optimizer 0.6.0
@angular-devkit/core 0.6.0
@angular-devkit/schematics 0.6.0
@ngtools/webpack 6.0.0
@schematics/angular 0.6.0
@schematics/update 0.6.0
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
Developing on Bash on Ubuntu on Windows 10 1803.
/home/myuser/dev
-> /mnt/d/dev
)ng new myNewProject
cd myNewPoject
ng generate component some-component
Could not find an NgModule. Use the skip-import option to skip importing in NgModule.
It should generate a new component as if you were not following the symlink.
Closing...
Duplicate of #10653
angular.json -->
projects: {
project_name-e2e:{} <-- delete
}
You must target the default project name like this:
ng generate component components/test --project {{projectName}}
@tianxiaozi Your solution worked ! Thanks a lot !!
I had accidentally deleted my app.module.ts
file. Restoring it helped in fixing the issue.
@NikolayDonev
your solution worked for me thank you very much
Check if your app.module.ts
lives in the app
folder.
I moved my app.module.ts file in a new folder named "modules". That's why I got that error. I moved back it into app folder and the issue is solved.
Try creating the component inside the "app" module which is inside src folder. It worked for me.
I found that you need to have a module file, with
import { NgModule } from '@angular/core';
In the path when you use a command like
ng generate module client-search
You can only use ng g c "component name" in the same folder as the file: "app-routing.module" because of the import that typescript is doing
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
angular.json -->
projects: {
}