npm3 如何决定安装平面还是嵌套? [英] How does npm3 decides to install flat vs. nested?

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

问题描述

我的项目依赖于 angular2 beta.6 和另一个依赖于 angular2 beta.0 的项目.

My project depends on angular2 beta.6 and another project that depends on angular2 beta.0.

我的项目的package.json

"dependencies": {
    "angular2": "2.0.0-beta.6",
    "another-project": "0.0.1"
}

package.json 用于另一个项目

"dependencies": {
    "angular2": "2.0.0-beta.0",
}

当我 npm install 我的项目时,它会安装 angular2 两次:

When I npm install my project, it installs angular2 twice:

  1. node_modules/angular2 (beta.6)
  2. node_modules/another-project/angular2 (beta.0)
  1. node_modules/angular2 (beta.6)
  2. node_modules/another-project/angular2 (beta.0)

试图了解 npm3 如何决定嵌套 angular2 beta.0.是不是因为两者都被称为angular2,因此它们不能都坐在顶层?

Trying to understand how npm3 decides to nest angular2 beta.0. Is it because both are called angular2 and hence they can not both sit at the top level?

推荐答案

试图了解 npm3 如何决定嵌套 angular2 beta.0.是不是因为两者都被称为angular2,因此它们不能都坐在顶层?

Trying to understand how npm3 decides to nest angular2 beta.0. Is it because both are called angular2 and hence they can not both sit at the top level?

是的,这是正确的.节点代码 require 是一个按名称命名的模块,使用如下代码:

Yes, this is correct. Node code require's a module by name, using code like this:

require('angular2');

Node 本身不知道不同的版本,这是 npm 的工作,所以它只是首先使用 require 路径中匹配的任何模块,依赖于匹配的目录名称.

Node itself is not aware of the different versions, that's the job of npm, so it just uses whatever module matches in the require path first, relying on matching directory names.

npm 通过在发生冲突时在每个模块的目录中安装特定版本来适应这一点,以便 require 路径将首先包含该版本.

npm accommodates this by installing specific versions in directories for each module when a conflict occurs, so that the require path will include that first.

这篇关于npm3 如何决定安装平面还是嵌套?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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