【记录解决】npm安装依赖报错:npm ERR! cb() never called! npm ERR! This is an error with npm i

2,610 阅读1分钟

npm安装依赖报错: npm ERR! cb() never called! npm ERR! This is an error with npm itself.

一. 问题描述

用npm安装依赖报错:

npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://npm.community>
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-12-16T07_38_47_793Z-debug.log

执行

npm config set ignore-engines true

命令 npm config set ignore-engines true 的作用是告诉 npm 在安装依赖时忽略 package.jsonengines 字段的版本要求。

详细解释:

package.json 文件中,开发者可以通过 engines 字段指定应用或包所支持的 Node.js 和 npm 版本。例如:

{
  "engines": {
    "node": ">=14.0.0",
    "npm": ">=6.0.0"
  }
}

这种配置可以确保应用或包在指定的 Node.js 或 npm 版本上运行。如果你当前的 Node.js 或 npm 版本不满足 engines 字段的要求,npm 可能会拒绝安装依赖。

使用 npm config set ignore-engines true 后:

  • npm 会忽略这些 engines 要求,即使你的 Node.js 或 npm 版本不符合 package.json 中的版本限制,npm 也会继续安装包。

何时使用?

  • 你可能使用较新的 Node.js 版本,但某些依赖项还没有更新 engines 要求,导致无法安装。
  • 你了解你的环境能支持这些依赖,但 engines 限制阻止了安装。

一般来说,这个设置适用于开发过程中灵活应对版本要求,但要注意它可能会导致一些潜在的兼容性问题。如果应用依赖某些特定版本的 Node.js 或 npm 功能,忽略 engines 可能会导致错误。