我的项目依赖于angular2 beta.6和另一个依赖于angular2 beta.0的项目.
package.json用于我的项目
"dependencies": {
"angular2": "2.0.0-beta.6",
"another-project": "0.0.1"
}
Run Code Online (Sandbox Code Playgroud)
package.json用于另一个项目
"dependencies": {
"angular2": "2.0.0-beta.0",
}
Run Code Online (Sandbox Code Playgroud)
当npm install我的项目,它安装angular2两次:
node_modules/angular2 (beta.6)node_modules/another-project/angular2 (beta.0)试图了解npm3如何决定嵌套angular2 beta.0.是因为它们都被称为angular2,因此它们不能同时坐在顶层吗?
尝试了解 npm3 如何决定嵌套 angular2 beta.0。是否因为两者都称为 angular2,因此它们不能同时位于顶层?
是的,这是正确的。节点代码require按名称命名为模块,使用如下代码:
require('angular2');
Run Code Online (Sandbox Code Playgroud)
Node 本身不知道不同的版本,这是 的工作npm,因此它只是首先使用 require 路径中匹配的任何模块,依赖于匹配的目录名称。
npm当发生冲突时,通过在每个模块的目录中安装特定版本来适应这一点,以便 require 路径将首先包含该版本。