question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 ❤️


Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
delastevecommented, Mar 4, 2017

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

2reactions
markgohocommented, Mar 1, 2017

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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

ng cli generate component with module broken - Stack Overflow
in this case bar component will be imported/exported by foo.module, but located under src/app. EASDIR error occurred because you provided a ...
Read more >
ng generate component using the CLI - Pluralsight
ng generate component is a simple one-line command which creates different files and a folder, and it references the newly created component ......
Read more >
ng generate - Angular
Run through and reports activity without writing out results. ... --root-module-class-name ... Include template inline in the root component.ts file.
Read more >
Angular Modules and NgModule - Complete Guide
Its useful for splitting up an application into smaller parts and lazy load each separately, and to create libraries of components that can ......
Read more >
A guide to Standalone Components in Angular - Ninja Squad
The Angular CLI team added a new flag --standalone to ng generate in ... The function expects the root standalone component as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found