Nx: make ngrx optional

Created on 29 Mar 2018  路  13Comments  路  Source: nrwl/nx

ngrx has a good competitor nrxs https://ngxs.gitbooks.io/ngxs/
nx uses ngrx by default.
Maybe giving another param to skip ngrx as package.json dependency?

question / discussion

Most helpful comment

@ThomasBurleson @jeffbcross I'd ask that we reconsider here, if possible.

I honestly believe the core offering of Nx isn't any particular integration with Ngrx -- I think it's safe to say that many Angular teams at enterprises don't use it -- but rather the scaffolding and control that it provides to developers that need to manage many distinct applications.

Being able to share components and resources across projects, complete with CLI support? That's _massive_ value. Seriously, that's huge. But while that would likely prove a significant time- and cost-saver for our clients, we have no intention to leverage any Ngrx functionality at this point.

I understand that we can use Nx as-is and make do (and simply ignore Ngrx), but it just feels like the message is a bit muddled here if they ship together. Per @FallenRiteMonk's comment, it seems as if Nx is already fairly decoupled from Ngrx as is, so removing it by default doesn't seem like _too_ large a stretch to ask for -- but please let me know if I'm totally off base here.

All 13 comments

@piernik - what do you mean by skip ngrx as a package.json dependency?

After generating new workspace package.json always contains

    "@ngrx/effects": "5.1.0",
    "@ngrx/router-store": "5.0.1",
    "@ngrx/store": "5.1.0",
    "@ngrx/store-devtools": "5.1.0", 
    "ngrx-store-freeze": "^0.2.1" 

We've discussed making NgRx optional. Personally I'd like to keep it, since the point of Nx is to be able to provide more value by being more prescriptive (and being able to provide more validation/enforcement because of that).

@jeffbcross can I simply delete all ngrx dependencies from package file?

Sure... If you are not using Ngrx in your code nor using DataPersistence.

Closing as will-not-change.

FYI right now deleting ngrx dependencies from package file gives errors when trying to build :

ERROR in node_modules/@nrwl/nx/src/data-persistence.d.ts(3,25): error TS2307: Cannot find module '@ngrx/effects'.
node_modules/@nrwl/nx/src/data-persistence.d.ts(4,31): error TS2307: Cannot find module '@ngrx/store'.

So it should be kept in the package json file even if not used

I have a project running NGXS without any problems if i delete all the NGRX dependencies, the only problem I have is if I also delete '@ngrx/schematics' from the dev-dependencies and then try to generate a new component:

Could not find module "@ngrx/schematics" from "<PROJECT_PATH>".
Error: Could not find module "@ngrx/schematics" from "<PROJECT_PATH>".
    at Object.resolve (<PROJECT_PATH>/node_modules/@angular-devkit/core/node/resolve.js:141:11)
    at NodeModulesEngineHost._resolvePackageJson (<PROJECT_PATH>/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:29:21)
    at NodeModulesEngineHost._resolveCollectionPath (<PROJECT_PATH>/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:70:40)
    at NodeModulesEngineHost.createCollectionDescription (<PROJECT_PATH>/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:106:27)
    at SchematicEngine._createCollectionDescription (<PROJECT_PATH>/node_modules/@angular-devkit/schematics/src/engine/engine.js:78:40)
    at SchematicEngine._createCollectionDescription (<PROJECT_PATH>/node_modules/@angular-devkit/schematics/src/engine/engine.js:89:48)
    at SchematicEngine.createCollection (<PROJECT_PATH>/node_modules/@angular-devkit/schematics/src/engine/engine.js:71:43)
    at Object.getCollection (<PROJECT_PATH>/node_modules/@angular/cli/utilities/schematics.js:28:31)
    at GenerateCommand.getOptions (<PROJECT_PATH>/node_modules/@angular/cli/models/schematic-command.js:193:41)
    at GenerateCommand.<anonymous> (<PROJECT_PATH>/node_modules/@angular/cli/commands/generate.js:38:53)

@ThomasBurleson @jeffbcross I'd ask that we reconsider here, if possible.

I honestly believe the core offering of Nx isn't any particular integration with Ngrx -- I think it's safe to say that many Angular teams at enterprises don't use it -- but rather the scaffolding and control that it provides to developers that need to manage many distinct applications.

Being able to share components and resources across projects, complete with CLI support? That's _massive_ value. Seriously, that's huge. But while that would likely prove a significant time- and cost-saver for our clients, we have no intention to leverage any Ngrx functionality at this point.

I understand that we can use Nx as-is and make do (and simply ignore Ngrx), but it just feels like the message is a bit muddled here if they ship together. Per @FallenRiteMonk's comment, it seems as if Nx is already fairly decoupled from Ngrx as is, so removing it by default doesn't seem like _too_ large a stretch to ask for -- but please let me know if I'm totally off base here.

@SamuelMS thanks for the input; it's helpful to know how Nx is used. I believe @vsavkin is in favor of making NgRx optional, but it hasn't been a high priority since upgrading to Angular CLI 6 is significant effort, and users can currently work around this by deleting the NxModule from their AppModule.

Any updates on this? Just like @paddyfink I get the following errors when building my project:

ERROR in node_modules/@nrwl/nx/src/data-persistence.d.ts(3,25): error TS2307: Cannot find module '@ngrx/effects'.
node_modules/@nrwl/nx/src/data-persistence.d.ts(4,31): error TS2307: Cannot find module '@ngrx/store'.

Why not make separate npm modules for different NX features? I am using NX just for architecture linting (for preventing libs using libs that should not depend on each other) and don't need the store handling. Static, development-only features like this should not be tied together with runtime ones.

If anyone knows how to set up this kind of linting yourself or knows a dedicated lib for it, please let me know.

@Mathyn make sure to remove the NxModule from your AppModule:
image

Was this page helpful?
0 / 5 - 0 ratings