如何强制npm 3安装嵌套依赖? [英] how can I force npm 3 to install nested dependencies?

查看:581
本文介绍了如何强制npm 3安装嵌套依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚升级到 npm版本3 ,并注意到其中一个最大的变化是它执行了一个平面依赖关系树。 p>

I just upgraded to npm version 3 and noticed one of the biggest changes it made is that it enforces a flat dependency tree.


您的依赖项现在将被安装最大化。在可能的情况下,所有的依赖项及其依赖项以及THEIR依赖项将被安装在项目的 node_modules 文件夹中,而不嵌套。当两个(或多个)模块具有冲突的依赖关系时,您只会看到嵌套在下面的模块。

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.

所以例如如果package A 取决于包 B ,当您 npm安装A 时,您将获得此文件结构:

So for example if package A is dependent on package B, when you npm install A you will get this file structure:

--- root/
 |--- node_modules/
   |--- A/
   |--- B/

而不是旧版文件结构从版本2或更低版本:

instead of the old file structure from version 2 or lower:

--- root/
 |--- node_modules/
   |--- A/
     |--- node_modules/
       |--- B/

第一个肯定不是最后一个)问题是这样的:

The first (and I’m sure not the last) problem I ran into was this:

A 不知道npm v3的行为,并且取决于包<强>乙即可。但是 A 假定旧(v2)文件结构,因为它的代码中具有 node_modules / B ,而不是正确的 ../ node_modules / B 。现在来自 A 的代码将无法编译,因为它在错误的目录中寻找 B /

Package A isn’t aware of npm v3’s behavior and is dependent on package B. But A assumes the old (v2) file structure because it has node_modules/B in its code, instead of the proper ../node_modules/B. Now the code from A won’t compile because it’s looking for B/ in the wrong directory.

如果我不想吝啬开发者修复代码并等待更新 A ,我想知道是否有一种方法可以设置一个选项,将强制npm将 A 的依赖项安装在自己的 node_modules 文件夹内,与npm v2完全相同。

If I don’t feel like nagging the developer to fix the code and waiting for an update of A, I wonder if there’s a way I can set an option that will force npm to install A’s dependencies inside its own node_modules folder, the same way npm v2 would have done it.

推荐答案

您是否尝试 - 旧版捆绑 npm install

https://docs.npmjs.com/cli / install


--legacy-bundling参数将导致npm安装软件包,使之在1.4之前的npm版本,如节点0.8附带的那个,可以安装该软件包。这消除了所有自动重复数据删除。

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 3安装嵌套依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆