2

I am new for nodejs. I have package.json like this

{
  ...
  "peerDependencies": {
    "react": "16.0.0"
  },

  "dependencies": {
    "some-lib-that-use-old-react": "git+ssh://git@bitbucket.org/xx/somelib.git",
    "other-lib-that-use-old-react": "git+ssh://git@bitbucket.org/xx/other.git"
  },
  ...
}

After I run npm install I get project tree like this

node_modules
|
|__some-lib-that-use-old-react
|__other-lib-that-use-old-react
|__react

I use peerDependencies because do not need react in some lib and other lib

(It work right that I expected)

But the version of react is not 16.0.0. It is old version from other lib.

Can I get react 16.0.0 with peerDependencies ?

I want one place of lib that I will use peerDependencies instead of dependencies.

I already try with npm-shrinkwrap.json like this

{
  "dependencies": {
    "react": { "version": "16.0.0", "from": "react@16.0.0" }
  }
}

But It is not work right with This version of npm is compatible with lockfileVersion@1, but npm-shrinkwrap.json was generated for lockfileVersion@0.

I use npm 5.5.1 & node 8.9.3. And do not have package-lock.json before install.

Thank everyone for come to help.

Update 1 I change OS from mac to windows but It does not work, too. npm cache clean --force not help, too.

Update 2 In package.json of react after npm i It look like this

{
  "_from": "react@old-version",
  "_id": "react@old-version",
  ...
  "_requiredBy": [
    "/some-lib-that-use-old-react",
    "/other-lib-that-use-old-react"
  ],
  ...
  "version": "old-version"
}

1 Answers1

0

From NPM document

One piece of advice: peer dependency requirements, unlike those for regular dependencies, should be lenient. You should not lock your peer dependencies down to specific patch versions. It would be really annoying if one Chai plugin peer-depended on Chai 1.4.1, while another depended on Chai 1.5.0, simply because the authors were lazy and didn't spend the time figuring out the actual minimum version of Chai they are compatible with.

Please understand peer dependencies support oldest version because the authors were lazy and didn't spend the time figuring out the actual minimum version of Chai they are compatible with.

See more : https://nodejs.org/en/blog/npm/peer-dependencies/


[Update on 2020-10-16]

Now in 2020.

NPM Version 7.0.0 make peerDependencies better than before and solve my old problem.

Please you check with this below link for more information.

https://github.com/npm/rfcs/blob/latest/implemented/0025-install-peer-deps.md/