如何强制 npm 3 安装嵌套依赖项?
how can I force npm 3 to install nested dependencies?
我刚刚升级到 npm version 3 and noticed one of the biggest changes it made is that it enforces a flat dependency tree。
Your dependencies will now be installed maximally flat. Insofar as is possible, all of your dependencies, and their dependencies, and THEIR dependencies will be installed in your project's node_modules
folder with no nesting. You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies.
因此,例如,如果包 A 依赖于包 B,当您 npm install A
时,您将获得此文件结构:
--- root/
|--- node_modules/
|--- A/
|--- B/
而不是版本 2 或更低版本的旧文件结构:
--- root/
|--- node_modules/
|--- A/
|--- node_modules/
|--- B/
我 运行 遇到的第一个(我肯定不是最后一个)问题是:
包 A 不知道 npm v3 的行为并且依赖于包 B。但是 A 采用旧的 (v2) 文件结构,因为它的代码中有 node_modules/B
,而不是正确的 ../node_modules/B
。现在来自 A 的代码无法编译,因为它在错误的目录中寻找 B/
。
如果我不想唠叨开发人员修复代码并等待 A 的更新,我想知道是否有办法设置一个选项强制 npm 在它自己的 node_modules
文件夹中安装 A 的依赖项,就像 npm v2 那样做。
这就是我睡眠不足时发生的情况。显而易见的解决方案以某种方式逃脱了我。
$ cd node_modules/A/
$ npm install
$ cd ../../
我刚刚 运行 解决了这个问题,并找到了解决这个问题的替代方法。由于 Node.js 带有 NPM,我能想到的唯一方法是降级到 Node.js 0.10 版本,它带有 NPM 上的旧版本,它将以旧方式安装依赖项。为了降级,我使用了 NVM 和 运行 nvm use 0.10.0
。你可以按照这个技巧在 npm 版本之间来回切换。希望对您有所帮助!
你试过 --legacy-bundling
npm install
吗?
https://docs.npmjs.com/cli/install
The --legacy-bundling argument will cause npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package. This eliminates all automatic deduping.
我刚刚升级到 npm version 3 and noticed one of the biggest changes it made is that it enforces a flat dependency tree。
Your dependencies will now be installed maximally flat. Insofar as is possible, all of your dependencies, and their dependencies, and THEIR dependencies will be installed in your project's
node_modules
folder with no nesting. You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies.
因此,例如,如果包 A 依赖于包 B,当您 npm install A
时,您将获得此文件结构:
--- root/
|--- node_modules/
|--- A/
|--- B/
而不是版本 2 或更低版本的旧文件结构:
--- root/
|--- node_modules/
|--- A/
|--- node_modules/
|--- B/
我 运行 遇到的第一个(我肯定不是最后一个)问题是:
包 A 不知道 npm v3 的行为并且依赖于包 B。但是 A 采用旧的 (v2) 文件结构,因为它的代码中有 node_modules/B
,而不是正确的 ../node_modules/B
。现在来自 A 的代码无法编译,因为它在错误的目录中寻找 B/
。
如果我不想唠叨开发人员修复代码并等待 A 的更新,我想知道是否有办法设置一个选项强制 npm 在它自己的 node_modules
文件夹中安装 A 的依赖项,就像 npm v2 那样做。
这就是我睡眠不足时发生的情况。显而易见的解决方案以某种方式逃脱了我。
$ cd node_modules/A/
$ npm install
$ cd ../../
我刚刚 运行 解决了这个问题,并找到了解决这个问题的替代方法。由于 Node.js 带有 NPM,我能想到的唯一方法是降级到 Node.js 0.10 版本,它带有 NPM 上的旧版本,它将以旧方式安装依赖项。为了降级,我使用了 NVM 和 运行 nvm use 0.10.0
。你可以按照这个技巧在 npm 版本之间来回切换。希望对您有所帮助!
你试过 --legacy-bundling
npm install
吗?
https://docs.npmjs.com/cli/install
The --legacy-bundling argument will cause npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package. This eliminates all automatic deduping.