node.js - 在 'npm' 的 'dependencies' 字段中添加 'package.json' 有什么意义吗?

标签 node.js npm package.json

我在某处看到了这个,在 package.json 中:

"dependencies": {
  ...,
  "npm": "^6.1.0",
  ...
}

这有什么意义吗?

npm 会因此更新自身吗?

如果是,如果当前版本低于6,是否可以这样做?

最佳答案

这不是包的正常做法。这不会影响您全局安装的 npm

如果你想指定你的包需要安装哪个版本的 npmpackage.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/

相关文章:

javascript - 该值不引用当前作用域,而是引用 ES6 箭头样式函数中的父作用域

javascript - 如何在 Node.js 中将 npm 请求模块与 bluebird 一起使用

node.js - NPM 包有过时的依赖项,有办法更改其版本吗?

node.js - NodeJS Spawn 不触发参数

node.js - inotify@1.4.1 : wanted {"os" :"linux" ,"arch" :"any"} 不支持的平台

php - composer.json 中 "conflict"的用法是什么,我该怎么做?

node.js - Node.JS 的默认文件夹功能

node.js - 错误 : write EPIPE at errnoException (net. js:770:11)

reactjs - VS Code 中的 create-react-app 在 Windows 上抛出未经授权的访问