bdefore / universal-redux

An npm package that lets you jump right into coding React and Redux with universal (isomorphic) rendering. Only manage Express setups or Webpack configurations if you want to.
MIT License
460 stars 48 forks source link

Using npm dependencies listed in Universal-redux on the project level #85

Closed sergesemashko closed 8 years ago

sergesemashko commented 8 years ago

Hi there,

There are some small and not critical points regarding dependencies that are listed in universal-redux and project that uses it, but, I think, solving them would be a good optimization:

There won't be a need to list common dependencies(like react, redux, and so on) that are already defined in universal-redux by having ./myProject/node_modules/universal-redux/node_modules in NODE_PATH. For example, https://github.com/bdefore/universal-redux-jwt/blob/master/package.json could get rid of:

  "devDependencies": {
    ...
    "react": "^0.14.3",
    "react-dom": "^0.14.3",
    "react-redux": "4.3.0",
    "react-router": "2.0.0-rc5",
    "react-router-redux": "3.0.0",
    "react-toolbox": "0.14.1"
  }
...

by having just "universal-redux": "^3.0.0" as a dependency.

I understand, that the solution might be an anti-pattern, but wonder if it makes sense.

I used such approach in my own universal-redux-like package, and if there is any interest I would be glad to implement this.

bdefore commented 8 years ago

@sergesemashko Version mismatching (particularly lodash) has presented issues with some of my projects as well.

Are you working with npm 2? I believe npm 3's flat dependency structure means you don't need to explicitly declare dependencies, and rely on universal-redux's dependencies instead. For example, the JWT example currently does not need to declare the dependencies you mention.

But that does not solve the issues I'm having where it appears UR does not always require the correct version between its dependencies and project level ones. I think adding UR's node_modules to NODE_PATH may have unintended consequences in the case where you wanted to use say an older version of lodash in your project. Then again, if UR specified project level node_modules before its own, perhaps that point is moot.

sergesemashko commented 8 years ago

@bdefore, I used npm 2 initially, but on npm@3 now and there are still cases when dependencies are not installed on “top” node_modules level, for example:

  1. Several dependencies have different sub-dependency version:
    • project A has dependency B and C
    • B has dependebcy D@1.0.0 -> D@1.0.0 will be installed in ./A/node_modules/B/node_modules/D
    • C has dependebcy D@2.0.0 -> D@2.0.0 will be installed in ./A/node_modules/C/node_modules/D
    • ./A/node_modules/D - not found, require('D') from A fails

2.In case A wants to use lower version of C:

./A/node_modules/universal-redux/node_modules should be appended (not prepended) toNODE_PATH to cover all the cases and avoid having the same dependencies already listed in universal-redux. I understand, that this is a bad practice, but I'm not aware of any other solution.

In case of version mismatching in dependencies between project and universal-redux webpack bundles both versions for client, what would be good to avoid.

sergesemashko commented 8 years ago

solved by adding ./node_modules/universal-redux/node_modules to NODE_PATH on the project. closing the issue