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

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

问题描述

我刚刚升级到 npm 版本 3 并注意到其中一个它所做的最大变化是它强制执行扁平依赖树.><块引用>

您的依赖项现在将被最大程度地安装.在可能的情况下,您的所有依赖项及其依赖项以及它们的依赖项将无嵌套地安装在您项目的 node_modules 文件夹中.只有当两个(或多个)模块存在相互冲突的依赖关系时,您才会看到模块相互嵌套.

例如,如果包 A 依赖于包 B,则当您 npm install A 时,您将获得以下文件结构:

--- root/|--- node_modules/|--- A/|--- 乙/

代替版本 2 或更低版本的旧文件结构:

--- root/|--- node_modules/|--- A/|--- node_modules/|--- 乙/

我遇到的第一个(我敢肯定不是最后一个)问题是:

A 不知道 npm v3 的行为并且依赖于包 B.但是 A 假定旧的 (v2) 文件结构,因为它的代码中有 node_modules/B,而不是正确的 ../node_modules/B>.现在 A 中的代码将无法编译,因为它在错误的目录中查找 B/.

如果我不想唠叨开发人员修复代码并等待A的更新,我想知道是否有办法设置一个选项来强制安装npmA 在其自己的 node_modules 文件夹中的依赖项,与 npm v2 相同.

解决方案

您是否尝试过 --legacy-bundling for npm install?

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

<块引用>

--legacy-bundling 参数将导致 npm 安装包,以便 npm 1.4 之前的版本,例如 node 0.8 中包含的版本,可以安装包.这消除了所有自动重复数据删除.

I just upgraded to 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.

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/

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:

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.

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.

解决方案

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

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