You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS下npx react-native init报错:找不到指定Node路径

解决方案

方法1:创建软链接修复路径

Homebrew安装的Node.js 20+版本调整了目录结构,lib目录被移至libexec下,直接创建软链接让npm能找到预期路径:

sudo ln -s /opt/homebrew/Cellar/node/20.6.1/libexec/lib /opt/homebrew/Cellar/node/20.6.1/lib

执行完后重新运行npx react-native init myproject即可。

方法2:重新安装Node.js

卸载当前路径异常的Node.js,通过Homebrew重新安装以确保目录结构正常:

brew uninstall node
brew install node

安装完成后用node -v和npm -v验证版本,确认路径无误后再初始化项目。

方法3:修正npm的prefix配置

检查npm的prefix设置是否指向错误路径,将其修正为Node.js的libexec目录:

# 查看当前prefix配置
npm config get prefix
# 设置正确的prefix路径
npm config set prefix /opt/homebrew/Cellar/node/20.6.1/libexec

设置完成后重启终端,再执行项目初始化命令。

方法4:改用Yarn初始化项目

绕开npm的路径问题,使用Yarn创建React Native项目:

# 安装Yarn
brew install yarn
# 创建项目
yarn create react-native-app myproject

内容的提问来源于stack exchange,提问作者gginchev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 23:24:53