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.*

Can also confirm uninstalling @angular/cli 6.0.0 and installing 6.0.1 fixed the generate issue for me - tested with component/service/module
A PR that is part of 6.0.1 will hopefully address this issue. Can @nginx17 and @matheusdavidson please confirm that v6.0.1 have resolved this issue for you?
@Brocco Thank you, problem solved for me
Thanks! 6.0.1 fixed the issue...
Sorry for the confusion. I started to figure out how to update my existing app to version 6.0.1 by answering my own questions. If it can help others, I'd like to share my process.
- Do I need to uninstall angular cli then reinstall angular cli and start over with an entirely new app?
I ask because I have already started building my 6.0.0 app and I am looking for the quickest way to get the same results when I run ng generate as did the celebratory github users who have posted successful results.
note: My steps below allowed me to update an existing app that had the ng generate error and before I did ng update locally I did a complete global uninstall and npm cache wipe.
npm uninstall -g @angular/cli
npm cache verify
# if npm version is < 5 then use `npm cache clean`
npm install -g @angular/cli@latest
- Should I run
ng updatewithin my 6.0.0 app? (ng updateonly updates local not global version@angular/coreand@anguar/clito version 6.0.1.ng updatetold me which update commands were available.)
Name Version Command to update
--------------------------------------------------------------------------------
@angular/cli 6.0.0 -> 6.0.1 ng update @angular/cli
@angular/core 6.0.0 -> 6.0.1 ng update @angular/core
-
After uninstall, cache verify and install of
@angular/cliglobally,ng generatewas still not working properly in existing 6.0.0 app. -
If I
cd ..out of the existing app and runng new app-namethen runng generate component testthe test component is generated with the proper path. -
To get this working in my exisitng app I had to uninstall locally by running
npm uninstall --save-dev angular-clithen I ranng update @angular/cliand then ranng update @angular/coreandng generate component testworks by ng updating the core and cli of an existing 6.0.0 app to version 6.0.1. -
I ran this command locally in my existing app to update all the other dependencies to version 6.0.1
ng update @angular-devkit/architect @angular-devkit/build-angular @angular-devkit/build-optimizer @angular-devkit/core @ngtools/webpackresult bellow.
Package not installed: "@angular-devkit/architect". Skipping.
Package not installed: "@angular-devkit/build-optimizer". Skipping.
Package not installed: "@angular-devkit/core". Skipping.
Package not installed: "@ngtools/webpack". Skipping.
Updating package.json with dependency @angular-devkit/build-angular @ "0.6.1" (was "0.6.0")...
When I run ng --version my existing app is up-to-date!
Angular CLI: 6.0.1
Node: 8.11.1
OS: darwin x64
Angular: 6.0.1
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.1
@angular-devkit/build-angular 0.6.1
@angular-devkit/build-optimizer 0.6.1
@angular-devkit/core 0.6.1
@angular-devkit/schematics 0.6.1
@ngtools/webpack 6.0.1
@schematics/angular 0.6.1
@schematics/update 0.6.1
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
ng generate service data works as well!
CREATE src/app/data.service.spec.ts (362 bytes)
CREATE src/app/data.service.ts (133 bytes)
In short, to fix ng generate issue:
For a new app
npm uninstall -g @angular/cli
npm cache verify
# if npm version is < 5 then use `npm cache clean`
npm install -g @angular/cli@latest
ng new app-name
For an existing app update
npm uninstall -g @angular/cli
npm cache verify
# if npm version is < 5 then use `npm cache clean`
npm install -g @angular/cli@latest
cd my-existing-app
npm uninstall --save-dev @angular/cli
npm cache verify
#if angular app version is < 6 update cli with this
npm install --save-dev @angular/cli@latest
#if angular app version is >= 6 update angular cli with this
ng update @angular/cli
#when angular cli 6 is installed into the app ng update will work
ng update @angular/core
ng update @angular-devkit/build-angular
@Brocco, its working with 6.0.1, thank you!
@Brocco still error in Windows x64, maybe a windows related error? Global angular cli install:
Angular CLI: 6.0.1
Node: 8.11.1
OS: win32 x64
$ ng new ng-demo --skip-install
Then edit angular.json, change sourceRoot to client and all other reference to src to client. New components installed in src (wrong!), without --skip-imports you get and error:
$ ng version
Angular CLI: 6.0.1
Node: 8.11.1
OS: win32 x64
Angular: 6.0.1
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.1
@angular-devkit/build-angular 0.6.1
@angular-devkit/build-optimizer 0.6.1
@angular-devkit/core 0.6.1
@angular-devkit/schematics 0.6.1
@ngtools/webpack 6.0.1
@schematics/angular 0.6.1
@schematics/update 0.6.1
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
$ ng g c core --skip-import --dry-run
CREATE src/app/core/core.component.html (23 bytes)
CREATE src/app/core/core.component.spec.ts (614 bytes)
CREATE src/app/core/core.component.ts (261 bytes)
CREATE src/app/core/core.component.css (0 bytes)
So can be reopened as it seems it's resolved? ping @Brocco
Hi @Brocco, I have the same problem as @gremo is having. I have tried iposton suggestion as well, but no luck.
Could you please help me to understand what I'm doing wrong?
I'm currently using windows 7 Angular CLI: 6.0.1 Node: 8.10.0 OS: win32 x64
I created a new project after installing cli 6.0.1 and updated all reference to 0.6.1/6.0.1
ng -v
Angular CLI: 6.0.1
Node: 8.10.0
OS: win32 x64
Angular: 6.0.1
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.1
@angular-devkit/build-angular 0.6.1
@angular-devkit/build-optimizer 0.6.1
@angular-devkit/core 0.6.1
@angular-devkit/schematics 0.6.1
@ngtools/webpack 6.0.1
@schematics/angular 0.6.1
@schematics/update 0.6.1
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
angular.json file:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"kcilds": {
"root": "",
"sourceRoot": "testApp",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/kcilds",
"index": "testApp/index.html",
"main": "testApp/main.ts",
"polyfills": "testApp/polyfills.ts",
"tsConfig": "testApp/tsconfig.app.json",
"assets": [
"testApp/favicon.ico",
"testApp/assets"
],
"styles": [
"testApp/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "testApp/environments/environment.ts",
"with": "testApp/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "kcilds:build"
},
"configurations": {
"production": {
"browserTarget": "kcilds:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "kcilds:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "testApp/test.ts",
"polyfills": "testApp/polyfills.ts",
"tsConfig": "testApp/tsconfig.spec.json",
"karmaConfig": "testApp/karma.conf.js",
"styles": [
"testApp/styles.css"
],
"scripts": [],
"assets": [
"testApp/favicon.ico",
"testApp/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"testApp/tsconfig.app.json",
"testApp/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"kcilds-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "kcilds:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "kcilds"
}
package.json file:
{
"name": "kcilds",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.1",
"@angular/common": "^6.0.1",
"@angular/compiler": "^6.0.1",
"@angular/core": "^6.0.1",
"@angular/forms": "^6.0.1",
"@angular/http": "^6.0.1",
"@angular/platform-browser": "^6.0.1",
"@angular/platform-browser-dynamic": "^6.0.1",
"@angular/router": "^6.0.1",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.1",
"@angular-devkit/build-angular": "~0.6.1",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.1",
"@angular/language-service": "^6.0.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
}
Regards
the same for me. Not working! I have tried all of the tips and suggestions stated above.
OS:
ProductName: Mac OS X
ProductVersion: 10.13.3
BuildVersion: 17D47
NG (ng version):
Angular CLI: 6.0.1
Node: 8.9.4
OS: darwin x64
Angular: 6.0.1
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.1
@angular-devkit/build-angular 0.6.1
@angular-devkit/build-optimizer 0.6.1
@angular-devkit/core 0.6.1
@angular-devkit/schematics 0.6.1
@angular/cdk 6.0.2
@angular/material 6.0.2
@ngtools/webpack 6.0.1
@schematics/angular 0.6.1
@schematics/update 0.6.1
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
angular.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"testproject": {
"root": "",
"sourceRoot": "client",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/public",
"index": "client/index.html",
"main": "client/main.ts",
"tsConfig": "client/tsconfig.app.json",
"polyfills": "client/polyfills.ts",
"assets": [
"client/assets",
"client/assets/favicon.ico"
],
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/font-awesome/css/font-awesome.min.css",
"client/styles.scss"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/tether/dist/js/tether.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
]
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "client/environments/environment.ts",
"with": "client/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "testproject:build",
"proxyConfig": "proxy.conf.json"
},
"configurations": {
"production": {
"browserTarget": "testproject:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "testproject:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "client/test.ts",
"karmaConfig": "./karma.conf.js",
"polyfills": "client/polyfills.ts",
"tsConfig": "client/tsconfig.spec.json",
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/tether/dist/js/tether.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
],
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/font-awesome/css/font-awesome.min.css",
"client/styles.scss"
],
"assets": [
"client/assets",
"client/assets/favicon.ico"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"client/tsconfig.app.json",
"client/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"testproject-e2e": {
"root": "",
"sourceRoot": "",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "./protractor.conf.js",
"devServerTarget": "testproject:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"e2e/tsconfig.e2e.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "testproject",
"schematics": {
"@schematics/angular:component": {
"prefix": "ht",
"styleext": "scss"
},
"@schematics/angular:directive": {
"prefix": "ht"
}
}
}
For those of you having the issue where it generates your files in the wrong folder (you're not using src as your sourceRoot) @SaoBiz found a work around over in the much more appropriately titled ticket that was closed as a duplicate of this one: #10702 . I still have this issue on CLI 6.0.7.
There is a workaround to get the CLI to generate the component/module/service/etc. in the correct location by using the (undocumented) --path option.
$ ng generate service app.config --path=Client
It looks like this was released in devkit 6.0.8 (CLI 6.0.8) but I'm still having the same problem:
PS C:\git\PrimeCore\Prime.Core> ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 6.0.8
Node: 10.3.0
OS: win32 x64
Angular: 6.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, 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.6.8
@angular/cdk 6.2.0
@angular/cli 6.0.8
@angular/flex-layout 6.0.0-beta.15
@angular/material 6.2.0
@ngtools/webpack 6.0.8
@schematics/angular 0.6.8
@schematics/update 0.6.8
rxjs 6.2.0
typescript 2.7.2
webpack 4.8.3
PS C:\git\PrimeCore\Prime.Core> ng g c shared/components/job-info
Could not find an NgModule. Use the skip-import option to skip importing in NgModule.
PS C:\git\PrimeCore\Prime.Core> ng g c /shared/components/job-info
Could not find an NgModule. Use the skip-import option to skip importing in NgModule.
PS C:\git\PrimeCore\Prime.Core> ng g c app/shared/components/job-info
Could not find an NgModule. Use the skip-import option to skip importing in NgModule.
PS C:\git\PrimeCore\Prime.Core> ng g c /app/shared/components/job-info
Could not find an NgModule. Use the skip-import option to skip importing in NgModule.
PS C:\git\PrimeCore\Prime.Core> ng g c /app/shared/components/job-info --path ClientApp
Could not find an NgModule. Use the skip-import option to skip importing in NgModule.
PS C:\git\PrimeCore\Prime.Core> ng g c shared/components/job-info --path ClientApp/app
CREATE ClientApp/app/shared/components/job-info/job-info.component.html (27 bytes)
CREATE ClientApp/app/shared/components/job-info/job-info.component.spec.ts (636 bytes)
CREATE ClientApp/app/shared/components/job-info/job-info.component.ts (278 bytes)
CREATE ClientApp/app/shared/components/job-info/job-info.component.scss (0 bytes)
UPDATE ClientApp/app/shared/shared.module.ts (1773 bytes)
and the angular.json which hasn't changed since upgrading to 6.0.0:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"prime-core-cli": {
"root": "",
"sourceRoot": "ClientApp",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
...
I also have this problem. Not sure if it helps but it looks like it's looking in the wrong directory for the NgModule. I think it's looking in the e2e directory instead of the src

Still broken; though maybe broken in a different way. It seems to be ignoring the 'defaultProject' setting, and instead yanking the last project out of the list of projects. If I reorder my angular.json file such that the -e2e project is first, and the standard project is second, then generation of a new component goes into the correct location, instead of attempting to drop into -e2e.
@darinclark Nailed it! I just tested by reordering my angular.json projects listing to put the e2e project first and the main project 2nd and then everything started working.
I found this already reported: https://github.com/angular/angular-cli/issues/11111
After upgrading cli to 6.0.8, cli is generating everything inside e2e folder.
@rfuhrer That worked for me!! Thanks.
Just pasting it here for others. Very simple fix for now.
It appears to just grab the last project in your angular.json. So if you have a main project and then a e2e project, reorder them so the main project is last and your default generate commands will go to the main project instead of e2e. If you need to generate something to the e2e project then you can use the --path e2e override
You can use "ng new you_project_name" copy angular.json paste to your original project directory.
this is still happening on 6.0.8.
This also still happened to me after moving the non e2e project after the others. And this happened to me because I ran 'ng update' on my project.
found the answer here: https://github.com/angular/angular-cli/issues/11111
basically, find the 'project name'-e2e set: "root": "e2e/", and remove: "sourceRoot": "e2e",
Worked by moving the e2e project in angular.json to top of the project list