安装 React-chartjs-2 Chart.js 时引擎“节点”与此模块不兼容,

The engine “node” is incompatible with this module when installing React-chartjs-2 Chart.js,

我正在使用 chart.js 及其 React 包装器创建圆环图。在新项目中运行良好,但无法在主项目中安装。

下面是一个运行良好的新项目示例。

下面是主要旧项目的示例,我无法安装它

错误:

The engine “node” is incompatible with this module

节点版本相同,您可以签入两个镜像。

您需要升级您的节点版本。由于您正在使用husky v4,您需要节点>=10

检查husky installation guide and The engine “node” is incompatible with this module

从日志中,我可以看出这是您当前使用的节点版本的问题。在您的日志中查看这一行

The engine "node" is incompatible with the module. Expected version ">=10". Got "8.10.0"

要解决这个问题,你可以试试这个

 1. Install nvm
 2. Download another version of node ">=10"
 3. Switch to that the latest version
 4. And try installing the module again

对于 Husky v7 上的任何人,并使用 VSCode

VSCode 可以使用与您的标准不同的 shell。在我的例子中,它使用 bash 而不是 zsh - 它没有安装 nvm,因此没有使用正确版本的节点。

修复:

  1. 在 VSCode 中打开命令面板 - + + P
  2. 类型Terminal: Select Default Profile
  3. Select 您设置了 nvm 或类似的终端。
  4. 重启VSCode