Skip to content

ng generate component --module doesn't support module names properly #7968

@shadowmint

Description

@shadowmint

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions