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 component --module doesn't support module names properly

See original GitHub issue

Bug 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:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
AhsanAyazcommented, Oct 8, 2017

Hi @shadowmint I guess there’s an issue with usual interpretation of the WIKI . It says :

Allows specification of the declaring module's file name (e.g `app.module.ts`).

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 to app folder).

E.g. for profile/profile-info/profile-info.module.ts, you’d have to specify the whole path. (relative to app 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 have foo-bar.module.ts at app folder.
  • ng generate component FooBarOne --module ./extra-module/ExtraModule considering path relative to app folder
7reactions
maccurtcommented, Oct 17, 2017

Sorry, 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…

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 >
Feature modules - Angular
A feature module collaborates with the root module and with other modules through the services it provides and the components, directives, and pipes...
Read more >
Add services - Angular
ng generate creates the component files in the src/app/messages directory and declares the MessagesComponent in AppModule . Edit the AppComponent template to ...
Read more >
NG8001: Unknown HTML element or component - Angular
Use the element name in the error to find the file(s) where the element is being used. Check that the name and selector...
Read more >
Upgrading from AngularJS to Angular
And this is not just for the sake of the upgrade - it is just solid advice in general! Using a Module Loaderlink....
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