Skip to content

ng generate error #10653

Closed
angular/devkit
#990

Description

@nginx17

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

screenshot from 2018-05-05 04-30-43

Activity

  1. WillsXiao commented on May 5, 2018

    @WillsXiao

    I have met the same issue.

  2. TedCorleone commented on May 5, 2018

    @TedCorleone

    @nginx17 @WillsXiao , try to restart the terminal, issue caused by new thread.

  3. WillsXiao commented on May 5, 2018

    @WillsXiao

    @TedCorleone I've tried it. It didn't work

  4. wdev1980 commented on May 5, 2018

    @wdev1980

    I have the same issue on OSX.

  5. nginx17 commented on May 5, 2018

    @nginx17
    Author

    @TedCorleone same as @WillsXiao didn't work
    I tried to restart the terminal and restart my computer but it still didn't work

  6. matheusdavidson commented on May 6, 2018

    @matheusdavidson

    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/

  7. matheusdavidson commented on May 6, 2018

    @matheusdavidson

    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
    
  8. stewones commented on May 6, 2018

    @stewones

    Same here

  9. sandangel commented on May 6, 2018

    @sandangel

    the generated file should be put in the default project. For now, you must specify the project name with --project projectName

  10. nginx17 commented on May 6, 2018

    @nginx17
    Author

    @sandangel still doesn't work

  11. sandangel commented on May 6, 2018

    @sandangel

    @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)
  12. nginx17 commented on May 6, 2018

    @nginx17
    Author

    @sandangel i try

    screenshot from 2018-05-06 23-50-30

    screenshot from 2018-05-07 00-03-03

    screenshot from 2018-05-06 23-52-46

    what i missed, angular.json default generated, not change

  13. matheusdavidson commented on May 6, 2018

    @matheusdavidson

    @sandangel, still not working

    captura de tela 2018-05-06 as 14 36 19

    It says there is no ngModule because its looking in the wrong place, what OS are you using?

  14. matheusdavidson commented on May 6, 2018

    @matheusdavidson

    If i try to create a module for example, it looks like it creates in the right place:
    captura de tela 2018-05-06 as 14 39 21

    but it doesn't:
    captura de tela 2018-05-06 as 14 39 44

  15. nginx17 commented on May 6, 2018

    @nginx17
    Author

    @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

  16. 60 remaining items

  17. grimace commented on Jun 25, 2018

    @grimace

    That didn't work for me, hence more digging and now works without moving projects in angular.json.

  18. dkteam commented on Jun 26, 2018

    @dkteam
  19. ivyblossom commented on Jun 26, 2018

    @ivyblossom

    Thanks @dkteam 👏
    It worked for me 🎉

  20. ZdebK commented on Jun 27, 2018

    @ZdebK

    For me worked that I changed the path. I was in src folder.
    cd ../
    fixed this :D

  21. PawelOwczarekFalcon commented on Jul 3, 2018

    @PawelOwczarekFalcon

    @grimace works fine :)

  22. agroupp commented on Jul 9, 2018

    @agroupp

    @grimace was very helpful, thanks

  23. chrisBosse commented on Jul 17, 2018

    @chrisBosse

    Very much like @grimace 's workaround above.

    For me, I was able to leave the project order the same in angular.json and only change the e2e project's"root" path.

    {
      "projects": {
        "myGreatApp": {
          "root": ""
        },
        "myGreatApp-e2e": {
          "root": "e2e"
          }
      }
    }    

    "projects"."myGreatApp-e2e"."root" changes from "" to "e2e" allowing the ng g module test command to build the module in the correct location. We don't use e2e so I don't know what else this breaks. Easy enough, as a workaround, to change and put back just before building an new module.

    Angular 6.0.6
    Angular CLI 6.0.8
    angular-devkit/schematics 0.6.8

  24. jgswiss commented on Jul 25, 2018

    @jgswiss

    Deleting the "e2e" in angular.json under:
    "app-e2e": {
    "root": "",
    "sourceRoot": "e2e",
    "projectType": "application"

    to

    "app-e2e": {
    "root": "",
    "sourceRoot": "",
    "projectType": "application",

    fixed my problem!

  25. Eternal21 commented on Jul 27, 2018

    @Eternal21

    Same problem on Windows, after upgrading to the latest cli (6.1.1). The solution that worked for me was suggested by @srkt

    1. Open angular.json (it should be right in the root of your app)
    2. Find "projects" property.
    3. Inside the project property you will see two children properties:
      "yourappname-app" and "yourappname-app-e2e"
    4. Switch their order (cut the "yourname-app-e2e" property and their children, and place them above "yourappname-app" property)
    5. I had to restart VS Code for it to start working (you may need to restart your terminal or whatever you're using)
  26. gremo commented on Jul 28, 2018

    @gremo

    I'm not having any problem changing the root folder from src to client with CLI version 6.1 (installed globally) on Windows 10 x64. Here is what I did:

    ng new ng-test --style scss --skip-install

    Save the patch file root-change.diff:

    diff --git a/angular.json b/angular.json
    index 56f7e2e..2d30500 100644
    --- a/angular.json
    +++ b/angular.json
    @@ -5,7 +5,7 @@
       "projects": {
         "ng-test": {
           "root": "",
    -      "sourceRoot": "src",
    +      "sourceRoot": "client",
           "projectType": "application",
           "prefix": "app",
           "schematics": {
    @@ -18,16 +18,16 @@
               "builder": "@angular-devkit/build-angular:browser",
               "options": {
                 "outputPath": "dist/ng-test",
    -            "index": "src/index.html",
    -            "main": "src/main.ts",
    -            "polyfills": "src/polyfills.ts",
    -            "tsConfig": "src/tsconfig.app.json",
    +            "index": "client/index.html",
    +            "main": "client/main.ts",
    +            "polyfills": "client/polyfills.ts",
    +            "tsConfig": "client/tsconfig.app.json",
                 "assets": [
    -              "src/favicon.ico",
    -              "src/assets"
    +              "client/favicon.ico",
    +              "client/assets"
                 ],
                 "styles": [
    -              "src/styles.scss"
    +              "client/styles.scss"
                 ],
                 "scripts": []
               },
    @@ -35,8 +35,8 @@
                 "production": {
                   "fileReplacements": [
                     {
    -                  "replace": "src/environments/environment.ts",
    -                  "with": "src/environments/environment.prod.ts"
    +                  "replace": "client/environments/environment.ts",
    +                  "with": "client/environments/environment.prod.ts"
                     }
                   ],
                   "optimization": true,
    @@ -71,17 +71,17 @@
             "test": {
               "builder": "@angular-devkit/build-angular:karma",
               "options": {
    -            "main": "src/test.ts",
    -            "polyfills": "src/polyfills.ts",
    -            "tsConfig": "src/tsconfig.spec.json",
    -            "karmaConfig": "src/karma.conf.js",
    +            "main": "client/test.ts",
    +            "polyfills": "client/polyfills.ts",
    +            "tsConfig": "client/tsconfig.spec.json",
    +            "karmaConfig": "client/karma.conf.js",
                 "styles": [
    -              "src/styles.scss"
    +              "client/styles.scss"
                 ],
                 "scripts": [],
                 "assets": [
    -              "src/favicon.ico",
    -              "src/assets"
    +              "client/favicon.ico",
    +              "client/assets"
                 ]
               }
             },
    @@ -89,8 +89,8 @@
               "builder": "@angular-devkit/build-angular:tslint",
               "options": {
                 "tsConfig": [
    -              "src/tsconfig.app.json",
    -              "src/tsconfig.spec.json"
    +              "client/tsconfig.app.json",
    +              "client/tsconfig.spec.json"
                 ],
                 "exclude": [
                   "**/node_modules/**"
    @@ -128,4 +128,4 @@
         }
       },
       "defaultProject": "ng-test"
    -}
    \ No newline at end of file
    +}
    diff --git a/client/tsconfig.app.json b/client/tsconfig.app.json
    index 8ea061e..7e02a41 100644
    --- a/client/tsconfig.app.json
    +++ b/client/tsconfig.app.json
    @@ -5,7 +5,7 @@
         "types": []
       },
       "exclude": [
    -    "src/test.ts",
    +    "client/test.ts",
         "**/*.spec.ts"
       ]
     }

    Apply the patch file and install vendor:

    git apply root-change.diff
    npm i

    All the following commands works:

    ng serve --open
    ng build --prod
    ng test
    ng e2e

    Component generation will correctly generate the component in the new root folder:

    ng g c home --dry-run
    CREATE client/app/home/home.component.html (23 bytes)
    CREATE client/app/home/home.component.spec.ts (614 bytes)
    CREATE client/app/home/home.component.ts (262 bytes)
    CREATE client/app/home/home.component.scss (0 bytes)
    UPDATE client/app/app.module.ts (388 bytes)
    
    $ ng g m core --dry-run
    CREATE client/app/core/core.module.spec.ts (259 bytes)
    CREATE client/app/core/core.module.ts (188 bytes)
  27. zachgoll commented on Sep 15, 2018

    @zachgoll

    My fix was fairly simple:

    Problem: I was running the command ng generate component components/home (create the "home" component in the components directory) from the location of angular-project/src/.

    Solution: Back out into the root of your angular project and specify the path you want the component to generate in like so:

    ng generate component src/components/home
    

    The above command should create a "home" component in the components/ directory inside the src/ directory.

    Hope that helps!

  28. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    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.

  29. locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions