Skip to content

"ng generate module/component" doesn't work as expected #5127

Closed

Description

@bboehm86

Please provide us with the following information:

OS?

  • Windows 10

Versions.

@angular/cli: 1.0.0-rc.0                      
node: 7.5.0                                   
os: win32 x64                                 
@angular/animations: 4.0.0-rc.1               
@angular/common: 4.0.0-rc.1                   
@angular/compiler: 4.0.0-rc.1                 
@angular/core: 4.0.0-rc.1                     
@angular/forms: 4.0.0-rc.1                    
@angular/http: 4.0.0-rc.1                     
@angular/platform-browser: 4.0.0-rc.1         
@angular/platform-browser-dynamic: 4.0.0-rc.1 
@angular/platform-server: 4.0.0-rc.1          
@angular/router: 4.0.0-rc.1                   
@angular/cli: 1.0.0-rc.0                      
@angular/compiler-cli: 4.0.0-rc.1             

Repro steps.

  1. run ng g m my-module - [ will work as expected ]

  2. decide that you want a module and routes, so run ng g m my-module --routing

  3. get asked if you want to override the old module, hit y

  4. get sad because the routing file was not created 😢

  5. decide that you want to add a component matching the module name, so run ng g c my-module

  6. get sad again because the new component got not added to your new my-module.module.ts but to your app.module.ts 😢

  7. be happy again because the Angular CLI is such a timesaver for most parts 😄👍

The log given by the failure.


Mention any other details that might be useful.

Thanks to the team for all the effort ❤️


Activity

  1. RicardoVaranda commented on Mar 1, 2017

    @RicardoVaranda
    Contributor

    Hi @bboehm86 ,

    I tried to repo your issue and I can confirm it happens on projects running cli RC0, I first tested on Beta.29 this issue was not present.

    For your last 2 points, it sounds like it's more of a new feature request to support adding components to specific modules. The thing is that the cli is in RC now which means no new features will be added until 2.0

    I'll have a look through the recent PR on module creation to see what can be causing the routing issue.

  2. bboehm86 commented on Mar 1, 2017

    @bboehm86
    Author

    Hey @RicardoVaranda ,

    thanks for having a look. 👍

    I'm not entirely sure that it is a new feature since I was under the impression that the new components will/should be added to the nearest module.
    But okay, we can achieve that in this case with ng g c my-module/my-module --flat for now. Feels a bit hacky though.

  3. markgoho commented on Mar 1, 2017

    @markgoho
    Contributor

    I'm having this issue, too. All new components are being added not to the nearest module, but to the root app.module. This is not a new feature....but it does appear to be broken. I can confirm that @bboehm86 suggestion of my-module/my-module --flat does produce the desired outcome of generating a component and having the CLI add it to the module in that director.

    After generating a new module ng g module home the command ng g component home --module=home produces the following error:

    Error: EISDIR: illegal operation on a directory, read
        at Object.fs.readSync (fs.js:656:19)
        at tryReadSync (fs.js:457:20)
        at Object.fs.readFileSync (fs.js:494:19)
        at Class.afterInstall (C:\Users\Nella\Documents\GitHub\pccRegistration\node_modules\@angular\cli\blueprints\component\index.js:207:34)
        at tryCatch (C:\Users\Nella\Documents\GitHub\pccRegistration\node_modules\rsvp\dist\rsvp.js:538:12)
        at invokeCallback (C:\Users\Nella\Documents\GitHub\pccRegistration\node_modules\rsvp\dist\rsvp.js:553:13)
        at publish (C:\Users\Nella\Documents\GitHub\pccRegistration\node_modules\rsvp\dist\rsvp.js:521:7)
        at flush (C:\Users\Nella\Documents\GitHub\pccRegistration\node_modules\rsvp\dist\rsvp.js:2373:5)
        at _combinedTickCallback (internal/process/next_tick.js:67:7)
        at process._tickCallback (internal/process/next_tick.js:98:9)
    
  4. self-assigned this
    on Mar 2, 2017
  5. filipesilva commented on Mar 2, 2017

    @filipesilva
    Contributor

    @Brocco can you weigh in?

  6. filipesilva commented on Mar 2, 2017

    @filipesilva
    Contributor

    Partially dupe of #4614

  7. alorle commented on Mar 3, 2017

    @alorle

    Same here:

    $ ng --version
    
    @angular/cli: 1.0.0-rc.1
    node: 6.10.0
    os: win32 x64
    @angular/common: 2.4.9
    @angular/compiler: 2.4.9
    @angular/core: 2.4.9
    @angular/forms: 2.4.9
    @angular/http: 2.4.9
    @angular/platform-browser: 2.4.9
    @angular/platform-browser-dynamic: 2.4.9
    @angular/router: 3.4.9
    @angular/cli: 1.0.0-rc.1
    @angular/compiler-cli: 2.4.9

    Steps:

    $ ng g module back --routing
    
    installing module
      create src\app\back\back-routing.module.ts
      create src\app\back\back.module.ts
    
    $ ng g component back\home --module back
    
    installing component
      create src\app\back\home\home.component.sass
      create src\app\back\home\home.component.html
      create src\app\back\home\home.component.spec.ts
      create src\app\back\home\home.component.ts
    EISDIR: illegal operation on a directory, read
    Error: EISDIR: illegal operation on a directory, read
        at Error (native)
        at Object.fs.readSync (fs.js:731:19)
        at tryReadSync (fs.js:486:20)
        at Object.fs.readFileSync (fs.js:534:19)
        at Class.afterInstall (C:\Users\alvaro\Desktop\testing\node_modules\@angular\cli\blueprints\component\index.js:190:34)
        at tryCatch (C:\Users\alvaro\Desktop\testing\node_modules\rsvp\dist\rsvp.js:538:12)
        at invokeCallback (C:\Users\alvaro\Desktop\testing\node_modules\rsvp\dist\rsvp.js:553:13)
        at publish (C:\Users\alvaro\Desktop\testing\node_modules\rsvp\dist\rsvp.js:521:7)
        at flush (C:\Users\alvaro\Desktop\testing\node_modules\rsvp\dist\rsvp.js:2373:5)
        at _combinedTickCallback (internal/process/next_tick.js:67:7)
        at process._tickCallback (internal/process/next_tick.js:98:9)

    The result is the expected unless the new component is not included in the module structure. In other words, the module does not declare the new component.

  8. added 2 commits that reference this issue on Mar 4, 2017
    6a499bb
    c33527f
  9. delasteve commented on Mar 4, 2017

    @delasteve
    Contributor

    @bboehm86, The issue is that by not specifying --flat the CLI thinks that it is going to create a folder and begin looking in the parent folder to that component. Part of me wants to say this is the correct functionality.

    @markgoho and @AlvaroOrduna, you will need to be more specific on the file you wish to use for your module.

    @markgoho: ng g component home --module=home/home.module
    @AlvaroOrduna: ng g component back\home --module back\back.module

    That said, I'll look into creating a PR for both of these issues. I'll let the CLI team determine what the correct functionality is.

    Side note: I incorrectly thought my other PR, #5218, fixed this issue. It does not.

  10. added 3 commits that reference this issue on Mar 4, 2017
    5039640
    e21ed05
    f92321f
  11. Brocco commented on Mar 6, 2017

    @Brocco
    Contributor

    Closing this one in favor of tracking it via #4614

  12. added 2 commits that reference this issue on Mar 6, 2017
    e8ff334
    01628e9
  13. added a commit that references this issue on Mar 8, 2017
    3515c3b
  14. added a commit that references this issue on Apr 12, 2017
    cd69373
  15. tiagocaetano commented on Aug 5, 2017

    @tiagocaetano

    I have same issue , when i try to generate the component, the cmd didn't create the files and the folder, inside the project.

    ERROR in C:/wamp64/www/p-page/src/app/app.module.ts (5,30): Cannot find module './app/cp1/cp1.component'.

    ERROR in ./app.module.ts
    Module not found: Error: Can't resolve './app/cp1/cp1.component' in 'C:\wamp64\www\p-page\src\app'
    @ ./app.module.ts 10:0-55
    @ ../main.ts
    @ multi webpack-dev-server/client?http://localhost:4200 ../main.ts
    webpack: Failed to compile.
    webpack: Compiling...
    Hash: b46038d9bcc98a16a342
    Time: 2868ms
    chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 177 kB {4} [initial]
    chunk {1} main.bundle.js, main.bundle.js.map (main) 5.44 kB {3} [initial] [rendered]
    chunk {2} styles.bundle.js, styles.bundle.js.map (styles) 10.5 kB {4} [initial]
    chunk {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.19 MB [initial]
    chunk {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry]

    ERROR in C:/wamp64/www/p-page/src/app/app.module.ts (5,30): Cannot find module './src/app/cp1/cp1.component'.

    ERROR in C:/wamp64/www/p-page/src/app/app.module.ts (5,30): Cannot find module './src/app/cp1/cp1.component'.

    ERROR in ./app.module.ts
    Module not found: Error: Can't resolve './src/app/cp1/cp1.component' in 'C:\wamp64\www\p-page\src\app'
    @ ./app.module.ts 10:0-59
    @ ../main.ts
    @ multi webpack-dev-server/client?http://localhost:4200 ../main.ts
    webpack: Failed to compile.


    @angular/cli: 1.2.7
    node: 6.10.2
    os: win32 x64
    @angular/animations: 4.3.3
    @angular/common: 4.3.3
    @angular/compiler: 4.3.3
    @angular/core: 4.3.3
    @angular/forms: 4.3.3
    @angular/http: 4.3.3
    @angular/platform-browser: 4.3.3
    @angular/platform-browser-dynamic: 4.3.3
    @angular/router: 4.3.3
    @angular/cli: 1.2.7
    @angular/compiler-cli: 4.3.3
    @angular/language-service: 4.3.3

    C:\wamp64\www\p-page\src\app>

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    How i can fix this ...

  16. angular-automatic-lock-bot commented on Sep 7, 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.

  17. locked and limited conversation to collaborators on Sep 7, 2019
  18. added a commit that references this issue on May 29, 2026
    2994684
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