Platform: Cannot Generate Store for Sub-Module using ngrx/schematics

Created on 2 May 2018  路  10Comments  路  Source: ngrx/platform

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ x ] Bug report  
[ ] Feature request
[ ] Documentation issue or request

What is the current behavior?


I am seeing an error when trying to create a new store on a sub-module. Currently it seems to just try and create a store for the root application instead of the sub-module I pointed it at.

Expected behavior:


It should create a store for my sub-module.

Minimal reproduction of the problem with instructions:


I haven't added much to my existing application than the CLI created so far. So I guess:
1) create a new project form the ngCLI
2) Add ngrx schematic
3) have it generate the root store and reducers using ng generate store State --root --module app.module.ts
4) create a sub-module using the ng CLI
5) try and add a store using the schematic for the sub-module

Version of affected browser(s),operating system(s), npm, node and ngrx:

Angular CLI: 1.7.4
Node: 10.0.0
OS: darwin x64
Angular: 5.2.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.7.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0

Other information:

ng generate module auth --flat false
create src/app/auth/auth.module.ts (188 bytes)
ng generate store Auth -m auth/auth.module.ts
error! src/app/reducers/index.ts already exists.

Maybe I just missed something? If you think I did just poke me in the right direction hopefully?

Schematics bug

All 10 comments

I've just followed the instructions at the schematics docs and it seems like you're right.
I don't know if this is fixable atm since the master is at v6.
But, a workaround is to cd into the module folder.

So in your case it should be:

ng generate module auth --flat false
cd src/app/auth
ng generate store Auth -m auth/auth.module.ts

This workaround will be fine for me. Hopefully, a solution to restore documented functionality can be found at some point though.

What version of schematics are you on? I know this worked previously with the example in the docs

ng generate module admin --flat false
ng generate store admin/Admin -m admin/admin.module.ts

I could reproduce it with:
Angular Cli 1.7.4
Angular-devkit schematics: 0.3.2
Ngrx schematics 5.2

If you want I could create a repo.

ngrx/schematics: ^5.2.0
angular-devkit/schematics: 0.3.2
Angular CLI: 1.7.4

Node 10.0.0 on my machine

No repro needed. Something may have changed on how paths are constructed.

Specifically using ng generate store admin/Admin -m admin/admin.module.ts where it's specifically admin/Admin as the module seems to work. The documented way as per https://github.com/ngrx/platform/blob/master/docs/schematics/store.md is just a single Admin.

I see. Can you submit a PR for the docs? We'll assist if you need help.

I can if that is the expected method. I will do that now and hope to have a PR after my lunch.

1012 Should correct the documentation

Was this page helpful?
0 / 5 - 0 ratings