我在某处看到了这个,在 package.json
中:
"dependencies": {
...,
"npm": "^6.1.0",
...
}
这有什么意义吗?
npm
会因此更新自身吗?
如果是,如果当前版本低于6,是否可以这样做?
最佳答案
这不是包的正常做法。这不会影响您全局安装的 npm
。
如果你想指定你的包需要安装哪个版本的 npm
,package.json
中的 engines
字段是放置它的适当位置。来自 the npm docs :
You can also use the “engines” field to specify which versions of npm are capable of properly installing your program. For example:
{ "engines" : { "npm" : "~1.0.20" } }
Unless the user has set the
engine-strict
config flag, this field is advisory only and will only produce warnings when your package is installed as a dependency.
npm
不会阻止安装包含 engines
中列出的不同版本的 npm
的软件包,但它会在控制台中警告它请求与您正在使用的版本不同的 npm
。
安装 npm
作为依赖项的唯一目的是,如果它是一个以某种方式需要直接使用 npm
的 API 的包(比如 node_modules/
分析器,或类似的东西)。
关于node.js - 在 'npm' 的 'dependencies' 字段中添加 'package.json' 有什么意义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54028388/