"ng generate module/component" doesn't work as expected
See original GitHub issuePlease 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.
-
run
ng g m my-module
- [ will work as expected ] -
decide that you want a module and routes, so run
ng g m my-module --routing
-
get asked if you want to override the old module, hit
y
-
get sad because the routing file was not created 😢
-
decide that you want to add a component matching the module name, so run
ng g c my-module
-
get sad again because the new component got not added to your new
my-module.module.ts
but to yourapp.module.ts
😢 -
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:
- Created 7 years ago
- Comments:10 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
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 commandng g component home --module=home
produces the following error: