node.js - node_module如何解决依赖关系
问题描述
假设我有一个xyz
库(我使用安装的npm install xyz --save
)和项目abc
node模块如何判断依赖是否应该在
abc/node_modules
还是abc/node_modules/xyz/node_modules
?
解决方案
node_modules
如果 "root" 中存在不兼容的版本,则将模块放置在嵌套中node_modules
。
iRohitBhatia 在对您问题的评论中所说的部分正确。但重要的因素不仅仅是版本 - 而是版本兼容性。
例子:
axios@0.21.1依赖于follow-redirects@^1.14.0
如果你package.json
这样定义你的
{
"dependencies": {
"axios": "0.21.1"
}
}
它安装在同一级别。
ls node_modules
axios
follow-redirects
ls node_modules/axios
# there is no nested `node_modules`
但是,如果您的 中有不兼容的版本follow-redirects
,node_modules
它会将兼容版本安装到嵌套的node_modules/axios/node_modules
.
{
"dependencies": {
"follow-redirects": "1.0.0",
"axios": "0.21.1"
}
}
ls node_modules
axios
debug
follow-redirects # the non-compatible `1.0.0` version
ms
ls node_modules/axios/node_modules
follow-redirects # the compatible version
推荐阅读
- python - 得到一点ROC曲线
- javascript - Javascript:如何让 Solace 会话保持活跃
- wordpress - 如何将最近的帖子添加到菜单中?
- php - 如何在 laravel 中启动同名队列的多个实例?
- image - 来自带有标签的嵌套目录的 Spark Dataframe
- arduino - 对从 A2DP (esp32) 接收的音频数据执行 FFT
- php - 如何解决我在 php 中的文件上传问题?
- tableau-api - Tableau 计数值
- r - R中的单变量逻辑回归
- c# - ASP.NET MVC - 在 Razor 页面中显示 JSON - foreach 的问题