Specified module does not exist Angular 6
Asked Answered
J

6

18

Can you tell me why I cannot use below CLI? It says Specified module does not exist. Same error for both CLI commands.

Note: I have upgraded this app from ng 5 to ng 6. Is that this error due to some issue on upgrading?

ng generate component messages --module=core

ng generate component messages --module=app

enter image description here

app.core.module.ts

export class CoreModule {
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: CoreModule
    };
  }
}

app.module.ts

export class AppModule { }

ng --version

Angular CLI: 6.0.8
Node: 8.11.2
OS: win32 x64
Angular: 6.0.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

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.3.2
@angular/cli                      6.0.8
@angular/material                 6.3.2
@angular/tsc-wrapped              0.5.2
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.2.1
typescript                        2.7.2
webpack                           4.8.3

package.json

{
  "name": "Abc",
  "version": "0.0.1",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "run-s build:client build:aot build:server",
    "buildclient": "ng build --prod --build-optimizer --app 0",
    "build:aot": "ng build --aot --app 1",
    "build:server": "webpack -p",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "dev": "ng build --prod =cd dist http-server",
    "build:firebase": "ng build --prod && cp src/manifest_app.json dist && firebase deploy"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "6.0.7",
    "@angular/cdk": "^6.3.2",
    "@angular/common": "6.0.7",
    "@angular/compiler": "6.0.7",
    "@angular/core": "6.0.7",
    "@angular/forms": "6.0.7",
    "@angular/http": "6.0.7",
    "@angular/material": "^6.3.2",
    "@angular/platform-browser": "6.0.7",
    "@angular/platform-browser-dynamic": "6.0.7",
    "@angular/platform-server": "6.0.7",
    "@angular/router": "6.0.7",
    "@angular/service-worker": "6.0.7",
    "@auth0/angular-jwt": "^2.0.0",
    "@cloudinary/angular": "^2.1.1",
    "@jaspero/ng2-confirmations": "^0.3.3",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.8",
    "@ng-select/ng-select": "^0.36.2",
    "@nguniversal/module-map-ngfactory-loader": "^5.0.0",
    "@types/moment": "^2.13.0",
    "angular2-useful-swiper": "^5.0.1",
    "cloudinary-core": "^2.4.0",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "jquery": "^3.2.1",
    "moment": "^2.20.1",
    "ng-pwa-tools": "0.0.15",
    "ng2-cloudinary": "^0.9.2",
    "ng2-file-upload": "^1.3.0",
    "ng2-img-max": "^2.1.15",
    "ng4-geoautocomplete": "^0.1.0",
    "ng4-loading-spinner": "^1.1.1",
    "ngx-bootstrap": "^2.0.2",
    "ngx-toastr": "^6.5.0",
    "ngx-youtube-player": "^0.1.0",
    "raven-js": "^3.26.3",
    "rxjs": "^6.2.1",
    "rxjs-compat": "^6.2.1",
    "swiper": "^3.4.2",
    "webrtc-adapter": "^6.1.4",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/cli": "6.0.8",
    "@angular/compiler-cli": "6.0.7",
    "@angular/language-service": "6.0.7",
    "@types/googlemaps": "^3.30.8",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/jquery": "^3.2.18",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "npm-run-all": "^4.1.2",
    "protractor": "~5.1.2",
    "ts-loader": "^3.5.0",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "2.7.2",
    "webpack-node-externals": "^1.6.0",
    "@angular-devkit/build-angular": "~0.6.8"
  }
}
Joselow answered 20/7, 2018 at 8:1 Comment(2)
I think you have to specify file name like this ng generate component messages --module=app.module.ts.Hyoscyamine
Same error for this too: ng generate component messages --module=app.module.ts @HyoscyamineJoselow
M
18

Below code works on latest CLI version.

ng generate component messages --module app.core.module

It doesn't requires .ts

If we want to create new component which points to specified module inside the folder, specify folder path. Folder path should root of app folder.

ng g c ./components/messages/messages --module message.module

Hope this helps.

Marquis answered 28/2, 2019 at 10:21 Comment(1)
Thanks this worked for creating a component under a folder where Module name is different from Folder nameOwlet
V
13

Please use the path relative to your base-href that is src/app

Try

ng generate component messages --module ./app.core.module.ts
Vidicon answered 20/7, 2018 at 8:37 Comment(9)
Same error for this too: ng generate component messages --module ./core.moduleJoselow
Sorry, I missed .ts please retry.Vidicon
Same error for this too: ng generate component messages --module ./core.module.tsJoselow
Whats your current directory location?Vidicon
Please see my post's image above.Joselow
Your module name was incorrect in command . Please retry with updated .Vidicon
Same error for this too: ng generate component messages --module ./app.core.module.tsJoselow
Same command working on my side. Hope your module should be annotated with @NgModule.Vidicon
Yes, It is there on all modules.Joselow
M
7

I stumbled upon this issue and solved it by using a command like below:

ng g c core/header --module core/core.module.ts

I used this command and got error:

ng g c core/header --module core.module.ts
Mechling answered 9/9, 2019 at 19:53 Comment(1)
Yes, for modules in subfolders I also had to specify the path twice like this, or else change to the subfolder first.Disorientate
S
4

You can save yourself time and effort, instead of adding the command --module ../path/to/name.module each time for a new component, just add this configuration in your angular.json file:

 "projects": {
    "projectName": {
      "schematics": {
        "@schematics/angular:component": {
          "module": "../path/to/name.module"
       //.... other config 

After that you can add a component as you would normally.

Sheepdip answered 5/7, 2020 at 21:52 Comment(1)
how do you define multiple modulesMope
W
2

Just to update below command worked for me :

ng g c complete-path-of-folder/ComponentName --module ../complete-path-of-folder/home.module.ts

Wilmington answered 21/12, 2021 at 10:14 Comment(0)
C
0

you must create a routing (in the parent componenet) before create a module.

ng g m componentParent --routing --flat true

after that ou can create a module:

ng g c messages --module coupens

NB: dont forget to delete ComponenetParentModule from app.module (or parentModule)

Clan answered 14/6, 2023 at 14:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.