Nx: `ng g service` with module option not working for lib modules.

Created on 21 Jan 2018  路  7Comments  路  Source: nrwl/nx

Not able to use --module option with ng g service command for libs modules.

How to reproduce:

ng g lib dashboard --routing --lazy --parent-module=apps/default/src/app/app.module.ts
ng g component components/header --app=dashboard 
ng g component components/footer --app=dashboard
ng g component containers/accounts --app=dashboard
# this returns  `Error: Specified module does not exist` 
ng g service services/account --app=dashboard --module=dashboard

This works fine for modules in apps folder.

ng g service core/services/InMemoryData --app=default --module=core --spec=false
bug

Most helpful comment

Angular 6 schematics no longe support passing --module when generating a service. You can pass --project instead.

Closing this issue.

All 7 comments

Could you provide a github repo reproducing the issue?

here is experimental workspace setup:
https://github.com/xmlking/nx-starter-kit

step-by-step instructions tor reproduce:
https://github.com/xmlking/nx-starter-kit/blob/master/PLAYBOOK.md

In the playbook , following commands not working

ng g directive directives/min  --app=shared --module=shared --export=true
ng g component components/entityTable --app=shared --module=shared --export=true
ng g service services/account --app=dashboard --module=dashboard

I noticed this works in simple case but fails if I want to generate in a specific sub-directory

This works:

ng g lib ThemePicker 
ng g service ThemeStorage --app=theme-picker --module=theme-picker  --dry-run
  create libs/theme-picker/src/theme-storage.service.spec.ts (411 bytes)
  create libs/theme-picker/src/theme-storage.service.ts (118 bytes)
  update libs/theme-picker/src/theme-picker.module.ts (265 bytes)

NOTE: Run with "dry run" no changes were made.

But if I want to generate service in a sub-directory , this command gives error

ng g service services/ThemeStorage --app=theme-picker --module=theme-picker  --dry-run
Error: Specified module does not exist
Specified module does not exist

I was able to reproduce the issue. This requires a fix in the CLI itself. I'll take a look at it.

Any progress on this one? I noticed it not being assigned to anyone, so wat wondering if it's still on the radar.

@vsavkin I was wondering if you could give an update on the status of this item. We prefer grouping libraries and components in subdirectories, but as @xmlking explained and reproduced in this item, the generator currently bugs.

Thank you.

Angular 6 schematics no longe support passing --module when generating a service. You can pass --project instead.

Closing this issue.

Was this page helpful?
0 / 5 - 0 ratings