ng generate error
Versions
Angular CLI: 6.0.0 Node: 8.9.1 OS: linux x64 Angular: 6.0.0 ... animations, cdk, cli, common, compiler, compiler-cli, core ... forms, http, language-service, material, platform-browser ... platform-browser-dynamic, platform-server, 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
Repro steps
ng g component home
Could not find an NgModule. Use the skip-import option to skip importing in NgModule.
ng g component home --skip-import (same as generate everything)
Success generate component but wrong path not inside "src" but create new folder in root "home/user/PATH/app-id/home/home.component.*

I have met the same issue.
@nginx17 @WillsXiao , try to restart the terminal, issue caused by new thread.
@TedCorleone I've tried it. It didn't work
I have the same issue on OSX.
@TedCorleone same as @WillsXiao didn't work I tried to restart the terminal and restart my computer but it still didn't work
same here on OSX, not only generates in the project root folder, but with all the path down to my project root folder.
My project: /var/www/project/
When i generate, for example, home module: /var/www/project/var/www/project/home/
Just generated a new angular 6 project and tried to generate a module or a component and had the same issue, i`m using the latest version:
Angular CLI: 6.0.0
Node: 9.10.1
OS: darwin 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
Same here
the generated file should be put in the default project. For now, you must specify the project name with --project projectName
@sandangel still doesn't work
@nginx17 notice that your project must be placed in the projectRoot folder configued in angular.json
ng g c home --project example
CREATE projects/example/src/app/home/home.component.css (0 bytes)
CREATE projects/example/src/app/home/home.component.html (23 bytes)
CREATE projects/example/src/app/home/home.component.spec.ts (614 bytes)
CREATE projects/example/src/app/home/home.component.ts (257 bytes)
UPDATE projects/example/src/app/app.module.ts (442 bytes)
@sandangel i try



what i missed, angular.json default generated, not change
@sandangel, still not working

It says there is no ngModule because its looking in the wrong place, what OS are you using?
If i try to create a module for example, it looks like it creates in the right place:

but it doesn't:

@matheusdavidson i think this is not about OS, you used OSX and i used Linux, but problem is same. i don't know how about windows
I am also having this problem.
Samesies. Having the problem as well. With brand new project generation -- default angular.json.
hi everyone, try this:
ng new newproj
ng g app example #generate another app
ng g c home --project example #generate component in example app
I guess your global ng cli was not updated to v6 or ng v6 does not recognize project not placed in "projects" folder. mine work fine:
ng new newproj
CREATE newproj/README.md (1024 bytes)
CREATE newproj/angular.json (3408 bytes)
CREATE newproj/package.json (1311 bytes)
CREATE newproj/tsconfig.json (384 bytes)
CREATE newproj/tslint.json (2805 bytes)
CREATE newproj/.editorconfig (245 bytes)
CREATE newproj/.gitignore (503 bytes)
CREATE newproj/src/environments/environment.prod.ts (51 bytes)
CREATE newproj/src/environments/environment.ts (631 bytes)
CREATE newproj/src/favicon.ico (5430 bytes)
CREATE newproj/src/index.html (294 bytes)
CREATE newproj/src/main.ts (370 bytes)
CREATE newproj/src/polyfills.ts (3194 bytes)
CREATE newproj/src/test.ts (642 bytes)
CREATE newproj/src/assets/.gitkeep (0 bytes)
CREATE newproj/src/styles.css (80 bytes)
CREATE newproj/src/browserslist (375 bytes)
CREATE newproj/src/karma.conf.js (964 bytes)
CREATE newproj/src/tsconfig.app.json (194 bytes)
CREATE newproj/src/tsconfig.spec.json (282 bytes)
CREATE newproj/src/tslint.json (314 bytes)
CREATE newproj/src/app/app.module.ts (314 bytes)
CREATE newproj/src/app/app.component.css (0 bytes)
CREATE newproj/src/app/app.component.html (1141 bytes)
CREATE newproj/src/app/app.component.spec.ts (986 bytes)
CREATE newproj/src/app/app.component.ts (207 bytes)
CREATE newproj/e2e/protractor.conf.js (752 bytes)
CREATE newproj/e2e/src/app.e2e-spec.ts (299 bytes)
CREATE newproj/e2e/src/app.po.ts (208 bytes)
CREATE newproj/e2e/tsconfig.e2e.json (213 bytes)
> [email protected] install /Users/sand/Downloads/newproj/node_modules/fsevents
> node install
[fsevents] Success: "/Users/sand/Downloads/newproj/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
> [email protected] install /Users/sand/Downloads/newproj/node_modules/node-sass
> node scripts/install.js
Cached binary found at /Users/sand/.npm/node-sass/4.9.0/darwin-x64-57_binding.node
> [email protected] postinstall /Users/sand/Downloads/newproj/node_modules/node-sass
> node scripts/build.js
Binary found at /Users/sand/Downloads/newproj/node_modules/node-sass/vendor/darwin-x64-57/binding.node
Testing binary
Binary is fine
> @angular/[email protected] postinstall /Users/sand/Downloads/newproj/node_modules/@angular/cli
> node ./bin/ng-update-message.js
added 1146 packages from 1269 contributors in 20.672s
Successfully initialized git.
##################################################################################
ng g c home --project newproj
CREATE src/app/home/home.component.css (0 bytes)
CREATE src/app/home/home.component.html (23 bytes)
CREATE src/app/home/home.component.spec.ts (614 bytes)
CREATE src/app/home/home.component.ts (261 bytes)
UPDATE src/app/app.module.ts (388 bytes)
@sandangel what do you mean by "ng v6 does not recognize project not placed in "projects" folder"? are you in a projects directory in your example? I assume all commands are run from the same directory level in your example
@johren01 I mean with a newly created project, cli will generate app files under "src" folder, but if we generate a new app, by ng g app, generated files will be placed under "projects" folder. So I think when using ng g c home --project projName, if the projName is not placed under "projects" folder, the generated path might be wrong. I have tried but mine works fine for both project under "src" folder and "projects" folder. So I think may be your global cli version was not upgraded to 6. That what I guess based on your provided information. I can't reproduce your issue now on my macOS machine