简体   繁体   English

npm如何管理传递模块?

[英]How does npm manage transitive modules?

If I have an A module in my application which uses a C module in version 1 and a B module that also uses this C module but in version 2, which version of C module my project will actually be using?如果我的应用程序中有一个 A 模块在版本 1 中使用 C 模块,而 B 模块也使用此 C 模块但在版本 2 中,我的项目实际使用哪个版本的 Z0D61F8370CAD1D412F870B84D143E?

Something like below:如下所示:

My project
|--- A module
     |--- C module version 1
|--- B module
     |--- C module version 2

When you run npm install npm looks for package.json dependencies and peers recursively and install them all in their own folders.当您运行npm install npm 会查找package.json在他们自己的依赖项中并安装所有它们。 and if two dependencies have same dependency with different semantic version you would have both of versions but in different folders.如果两个依赖项具有不同语义版本的相同依赖项,则您将拥有两个版本,但位于不同的文件夹中。 For example in a project you might have about 20 thousand dependencies and all of them are installed by npm on node_module folder and that's why the folder is soooo big.例如,在一个项目中,您可能有大约 20,000 个依赖项,并且所有依赖项都由npm安装在 node_module 文件夹中,这就是该文件夹非常大的原因。

No. You no need to care about sub node_module inside A module or B module.不,您无需关心 A 模块或 B 模块中的子节点模块。 What you should care is how to use module A and B. Unless you want to use module C in side your code, u must install it independently.您应该关心的是如何使用模块 A 和 B。除非您想在代码中使用模块 C,否则您必须独立安装它。 For example:例如:

npm install C

In this case all module A, B and C are folders which same level.在这种情况下,所有模块 A、B 和 C 都是同一级别的文件夹。

node_module/
---Module A
     |---Module C (1)
---Module B
     |---Module C (2)
---Module C (*)

Summary: module C (*) is different with Module C (1) and (2).总结:模块 C (*) 与模块 C (1) 和 (2) 不同。 Maybe same version or different version.可能是同一个版本,也可能是不同的版本。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM