简体   繁体   English

为什么npm分别安装时会安装相同依赖项的两个不同版本

[英]Why does npm install two different version of the same dependency when installed separately

Scenario 1 场景1

Terminal : Windows cmd 终端 :Windows cmd

node version : v8.0.0 节点版本v8.0.0

npm version : v5.5.1 npm版本v5.5.1

I have a package.json where I specifically mention 我有一个package.json ,我特别提到

"@swimlane/ngx-charts": "^7.3.0",
"@swimlane/ngx-graph": "^4.3.0",

These have a subdependency on d3-scale . 这些对d3-scale有从属关系。

In this scenario the npm install command installs d3-scale: v2.0.0 which has dist/ folder in it. 在这种情况下, npm install命令将安装d3-scale: v2.0.0 ,其中包含dist/文件夹。 (Note: I use d3-scale/dist in a systemjs.config.js file for an Angular App) (注意:我在Angular App的systemjs.config.js文件中使用d3-scale/dist

Scenario 2 方案2

Terminal : Windows Subsystem For Linux ( bash for ubuntu for windows ) 终端 :Windows子系统(对于Linux)( bash for ubuntu for windows Windows bash for ubuntu for windows

node version : v8.11.1 节点版本v8.11.1

npm version : v5.6.0 npm版本v5.6.0

I perform npm install with the same package.json and this time it provides me with d3-scale: v1.0.7 which has build/ folder instead of dist/ quick comparison on d3-scale . 我使用相同的package.json执行npm install ,这一次它为我提供了d3-scale: v1.0.7 ,它具有build/文件夹,而不是d / scale上dist/ 快速比较

Now because of this discrepancy I had to change my systemjs.config.js to point to build for a local machine. 现在,由于这种差异,我不得不更改systemjs.config.js使其指向为本地计算机build的代码。

If the app gets deployed on the server or a cloud I am not sure which d3-scale it might download in the node_modules and I might have to commit a hotfix for it. 如果该应用程序已部署在服务器或云上,我不确定它可能会在node_modules下载哪个d3-scale ,并且我可能必须为此提交一个修补程序。

Question

Why is there a discrepancy in the first place? 为什么首先存在差异? What is causing this? 是什么原因造成的?

It seems that the NPM team resolved an issue in v5.6.0. NPM团队似乎解决了v5.6.0中的一个问题。

Fully cross-platform package-lock.json. 完全跨平台的package-lock.json。 Installing a failing optional dependency on one platform no longer removes it from the dependency tree, meaning that package-lock.json should now be generated consistently across platforms! 在一个平台上安装失败的可选依赖项不再将其从依赖项树中删除,这意味着package-lock.json现在应该在所有平台上一致地生成!

Source 资源

So try to upgrade your windows NPM to v5.6.0. 因此,请尝试将Windows NPM升级到v5.6.0。 It should work now. 现在应该可以工作了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么“npm install”会删除我在 angular cli 中安装的软件包? - Why does 'npm install' remove my installed packages in angular cli? 为什么`npm install`为同一个`package.json`文件生成不同的`package-lock.json`文件? - Why does `npm install` generate different `package-lock.json` files for the same `package.json` file? NPM 版本 2 安装版本为版本 8 时出错 - NPM version 2 error when installed version is version 8 'npm 是否安装'l<package_name> 安装一个package的最新版本还是安装最新版本的node兼容?</package_name> - Does 'npm instal'l <package_name> install the latest version of a package or the latest compatible with the version of node installed? 使用 npm 安装时 Node-gyp 版本不同 - Node-gyp version is different when using npm install 仅当用户手动安装我的npm软件包时,是否有好的方法来运行脚本?(不是通过依赖项安装的) - Is there good way to run a script only when the user install my npm package manually?(not installed by dependency) 为什么yarn install检出github仓库依赖项,而npm install却没有呢? - Why does yarn install checkout a github repository dependency but npm install does not? 卸载使用不同版本的npm安装的bower - Uninstalling bower installed with a different version of npm “ npm -v”给出的版本与安装的版本不同吗? - “npm -v” give different version than is installed? 为什么“ npm install”告诉我“未安装,您必须自己安装对等依赖项:”? - Why does “npm install” tell me “none is installed You must install peer dependencies yourself:”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM