运行expo start遇UnhandledPromiseRejectionWarning及语法错误求助
解决Expo Start时出现的SyntaxError: Unexpected token =错误
这个错误的核心原因是你的Node.js版本过低,不支持@expo/cli编译代码中使用的ES类字段语法(name = "ApiV2Error"属于ES2022的类属性特性,旧版Node无法解析)。
解决步骤:
检查当前Node.js版本:
node -v如果版本低于v16.x(或v14.x早期版本),必须升级。
升级Node.js(推荐用nvm管理版本):
- 安装nvm(MacOS可通过Homebrew:
brew install nvm) - 安装最新长期支持版Node:
nvm install --lts - 切换到该版本:
nvm use --lts
- 安装nvm(MacOS可通过Homebrew:
重新安装全局Expo CLI:
- 卸载旧版本:
yarn global remove @expo/cli - 重新安装:
yarn global add @expo/cli
- 卸载旧版本:
(可选)清理Yarn缓存并重新安装项目依赖:
yarn cache clean yarn install
完成以上步骤后,再次运行expo start即可正常启动项目。
内容的提问来源于stack exchange,提问作者HurrayChak
相关产品推荐
相关产品推荐

