nodejs版本问题.md 1.7 KB

解决node版本兼容性问题

error react-router-dom@7.12.0: The engine "node" is incompatible with this module. Expected version ">=20.0.0". Got "18.18.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

方法一:使用 nvm (Node Version Manager) 切换 Node 版本 Windows 安装 nvm:

下载 nvm-windows:https://github.com/coreybutler/nvm-windows/releases

下载 nvm-setup.exe 并安装

安装完成后,以管理员身份打开 PowerShell 或 CMD

安装并使用 Node.js 20 版本:

bash

查看可用的 Node.js 20 版本

nvm list available

安装 Node.js 20(选择最新的 20.x 版本)

nvm install 20.18.0

使用 Node.js 20

nvm use 20.18.0

验证版本

node --version

Yarn 设置国内镜像地址有以下几种方法:

  1. 设置淘宝 NPM 镜像(推荐) 查看当前镜像地址 yarn config get registry #淘宝最新镜像地址(推荐) yarn config set registry https://registry.npmmirror.com

设置 Cypress 镜像加速 bash

设置 Cypress 镜像(使用淘宝镜像)

yarn config set cypress:https://registry.npmmirror.com/binary.html?path=cypress/ binary_mirror https://cdn.cypress.io

yarn config set cypress_download_binary_url https://npmmirror.com/mirrors/cypress/

或者设置环境变量(Windows PowerShell)

$env:CYPRESS_INSTALL_BINARY = "https://npmmirror.com/mirrors/cypress/13.17.0/cypress.zip"

C:\Users\Administrator>yarn config set cypress_download_binary_url https://npmmirror.com/mirrors/cypress/ yarn config v1.22.22 success Set "cypress_download_binary_url" to "https://npmmirror.com/mirrors/cypress/". Done in 0.13s.

C:\Users\Administrator>