防止 npm 安装不支持的 Node.js 版本

确保设置项目的使用特定的 Node.js 版本,使开发人员在 git clonegit pull 您的项目时,可以正常运行项目。

我们可以通过在 package.json中设置 engines 属性来指定版本范围。

{
  "engines": {
    "node": ">=15.0.0"
  }
}

许多项目定义了 engine 属性,但没有强制执行所需的 Node.js 版本。在不支持 Node.js 版本的项目中运行 npm install 时,将显示以下警告(EBADENGINE)。

$ npm install

# npm WARN EBADENGINE Unsupported engine {
# npm WARN EBADENGINE   package: '[email protected]',
# npm WARN EBADENGINE   required: { node: '>=15.0.0' },
# npm WARN EBADENGINE   current: { node: 'v14.16.0', npm: '7.6.

你可能感兴趣的:(npm,node.js,前端,vue.js,javascript)