react 17.0.1 yarn install 时 node 16.17.0 不满足要求

483 阅读1分钟

环境:

node:v16.17.0

react: 17.0.1

现象描述:

在 yarn install react 17.0.1 时,node 报如下错误:

AssertionError [ERR_ASSERTION]: Current node version is not supported for development, expected "16.17.0" to satisfy "8.x || 9.x || 10.x || 11.x || 12.x || 13.x || 14.x".
    at Object.<anonymous> (/Users/bytedance/Documents/my-learn/react/node_modules/fbjs-scripts/node/check-dev-engines.js:46:3)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

解决方案:

升级 node,将 node 升级为 18.12.0(latest) 即可,在此推荐 fnm 管理 node 版本,安装步骤参考官网,升级过程如下:

fnm install 18.12.0 # 安装指定版本
fnm use 18.12.0 # 切换 node version
fnm list # 查看 fnm 管理的 node version 列表
fnm current # 查看当前 node 版本