使用Yarn创建TypeScript版React项目遇Node版本兼容问题求助
Hey there, let's tackle this Node version issue you're facing head-on. The core problem here is your current Node version (13.5.0) doesn't meet the minimum requirement for browserslist@4.14.7—it needs Node >=13.7 or one of the specified older versions. Updating brew and Yarn alone won't fix this, but we can adjust your Node version safely without losing any existing content.
Recommended Solution: Use Node Version Manager (nvm) to Manage Multiple Node Versions
nvm is a tool that lets you switch between different Node versions seamlessly. This way, you can keep your existing projects on their current Node versions while using a compatible one for this new React app. Here's how to set it up:
Install nvm via brew (since you're already using brew):
brew install nvmAfter installation, add these lines to your shell configuration file (like
~/.zshrcor~/.bashrc) to initialize nvm every time you open a terminal:export NVM_DIR="$HOME/.nvm" [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"Restart your terminal or run
source ~/.zshrc(or your respective config file) to apply the changes.Install a compatible Node version
You can either install the minimum required version (13.7.0) or opt for a more stable LTS version like 14.x (recommended for long-term support):# Install Node 14 (LTS) nvm install 14Switch to the new Node version
nvm use 14To set this as your default version for new terminals, run:
nvm alias default 14Re-run the create-react-app command
yarn create react-app mobx_course --template typescriptThis should now execute without the engine incompatibility error.
Temporary Workaround: Ignore Engine Checks (Not Recommended)
If you need a quick fix and don't want to upgrade Node right now, you can tell Yarn to skip engine compatibility checks. Keep in mind this might lead to unexpected issues down the line:
yarn create react-app mobx_course --template typescript --ignore-engines
Why Your Previous Updates Didn't Work
Updating brew and Yarn only refreshes those tools—your Node version stayed at 13.5.0, which is still below the >=13.7 requirement from browserslist. Using nVM ensures multiple Node versions can coexist, so you won't disrupt any existing projects that rely on older Node versions.
内容的提问来源于stack exchange,提问作者user12173449

