【发布时间】:2018-01-04 14:48:59
【问题描述】:
我是 nodejs 的新手。我有这样的 package.json
{
...
"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"
},
...
}
在我运行npm install 之后,我得到了这样的项目树
node_modules
|
|__some-lib-that-use-old-react
|__other-lib-that-use-old-react
|__react
我使用 peerDependencies 因为在some lib 和other lib 中不需要react
(它工作正常,我期望)
但是react的版本不是16.0.0。它是其他库的旧版本。
我可以用peerDependencies 反应 16.0.0 吗?
我想要一个 lib 位置,我将使用 peerDependencies 而不是 dependencies。
我已经像这样尝试npm-shrinkwrap.json
{
"dependencies": {
"react": { "version": "16.0.0", "from": "react@16.0.0" }
}
}
但它不适用于This version of npm is compatible with lockfileVersion@1, but npm-shrinkwrap.json was generated for lockfileVersion@0.
我使用npm 5.5.1 & node 8.9.3。并且安装前没有package-lock.json。
感谢大家前来帮忙。
更新 1 我将操作系统从 mac 更改为 windows,但它也不起作用。 npm cache clean --force 也无济于事。
更新2在npm i之后react的package.json中是这样的
{
"_from": "react@old-version",
"_id": "react@old-version",
...
"_requiredBy": [
"/some-lib-that-use-old-react",
"/other-lib-that-use-old-react"
],
...
"version": "old-version"
}
【问题讨论】:
-
尝试删除
node_modules文件夹并再次运行npm i -
对不起,我再试一次并点击链接,但它不再起作用。我尝试了 mac 和 windows,但结果相同。
标签: node.js reactjs npm npm-install