ng generate component --module doesn't support module names properly
See original GitHub issueBug Report or Feature Request (mark with an x
)
- [x] bug report
- [ ] feature request
Versions.
$ ng version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
@angular/cli: 1.4.5
node: 8.2.1
os: win32 x64
@angular/animations: 4.4.4
@angular/cli: 1.4.5
@angular/common: 4.4.4
@angular/compiler: 4.4.4
@angular/core: 4.4.4
@angular/forms: 4.4.4
@angular/http: 4.4.4
@angular/platform-browser: 4.4.4
@angular/platform-browser-dynamic: 4.4.4
@angular/router: 4.4.4
@angular/compiler-cli: 4.4.4
@angular/language-service: 4.4.4
typescript: 2.3.4
Repro steps.
$ ng new
...
$ ng generate module TestMod
create src/app/test-mod/test-mod.module.ts (191 bytes)
$ ng generate component TestComp --module test-mod.module.ts
Error: Specified module does not exist
Specified module does not exist
The log given by the failure.
Error: Specified module does not exist
Desired functionality.
Support a meaningful parameter value; either a path to a file, or a module name. ie. One of:
ng generate component Foo --module FooBar
ng generate component Foo --module ./src/app/foo-bar/foo-bar.module.ts
Mention any other details that might be useful.
Previously this worked (1.3.x): ng generate component Foo --module Bar
, (although ng generate component Foo --module FooBar
never did).
However, the wiki (https://github.com/angular/angular-cli/wiki/generate-component) now suggests:
ng generate component Foo --module bar.module.ts
…but that doesn’t work either.
By adding a console log to node_modules/@schematics/angular/utility/find-module.js
to log the base path, you can see it failing to find the correct path:
$ ng generate component FooBarOne --module FooBar
Attempting to resolve using base path: /src/app/FooBar
Error: Specified module does not exist
Specified module does not exist
$ ng generate component FooBarOne --module ./src/app/foo-bar/foo-bar.module.ts
Attempting to resolve using base path: /src/app/src/app/foo-bar/foo-bar.module.ts
Error: Specified module does not exist
Specified module does not exist
$ ng generate component FooBarOne --module foo-bar.module.ts
Attempting to resolve using base path: /src/app/foo-bar.module.ts
Error: Specified module does not exist
Specified module does not exist
In fact, it turns out the ‘correct’ invocation is:
$ ng generate component FooBarOne --module ./foo-bar/foo-bar.module.ts
Attempting to resolve using base path: /src/app/foo-bar/foo-bar.module.ts
create src/app/foo-bar-one/foo-bar-one.component.html (30 bytes)
create src/app/foo-bar-one/foo-bar-one.component.spec.ts (651 bytes)
create src/app/foo-bar-one/foo-bar-one.component.ts (302 bytes)
create src/app/foo-bar-one/foo-bar-one.component.scss (0 bytes)
This both changes the previous behaviour and contradicts the wiki, so although I can vaguely see how this might be some kind of ‘intended’ behaviour (automatically resolve the src path), it seems like a regression to me.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (2 by maintainers)
Hi @shadowmint I guess there’s an issue with usual interpretation of the WIKI . It says :
Since
app.module.ts
is inside the app folder, that makes total sense. For any subfolders, you’d have to specify the whole path (relative toapp
folder).E.g. for
profile/profile-info/profile-info.module.ts
, you’d have to specify the whole path. (relative toapp
folder)I’ll try to update the wiki, also I’ll try to make these work also,
ng generate component FooBarOne --module FooBar
considering we havefoo-bar.module.ts
atapp
folder.ng generate component FooBarOne --module ./extra-module/ExtraModule
considering path relative toapp
folderSorry, this is confusing at best. I finally got it work, only because I came across this thread. The trick for me was to remember it is relative to the app folder…