error Unexpected token = 从 RN 0.64.2 升级到 0.65.1 之后

Posted

技术标签:

【中文标题】error Unexpected token = 从 RN 0.64.2 升级到 0.65.1 之后【英文标题】:error Unexpected token = after upgrading from RN 0.64.2 to 0.65.1 【发布时间】:2021-11-10 19:30:32 【问题描述】:

我刚刚按照升级助手从 64.1 升级到 65.1。

但我开始收到此错误并且无法修复它。

我已将 node/npm 升级到 14.17 并完成了我能想到的所有其他事情。有人可以帮忙吗?

在构建期间发生此错误。

SyntaxError: Unexpected token =

块引用 22:55:32 > 任务:react-native-community_masked-view:compileReleaseLibraryResources 22:55:32 22:55:32 > 任务:app:bundleReleaseJsAndAssets 失败 22:55:32

22:55:32 /node_modules/metro/src/Server.js:350
22:55:32 processRequest = (req, res, next) => 
22:55:32 ^
22:55:32
22:55:32 SyntaxError: Unexpected token =
22:55:32 at new Script (vm.js:79:7)
22:55:32 at createScript (vm.js:251:10)
22:55:32 at Object.runInThisContext (vm.js:303:10)
22:55:32 at Module._compile (internal/modules/cjs/loader.js:656:28)
22:55:32 at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
22:55:32 at Module.load (internal/modules/cjs/loader.js:598:32)
22:55:32 at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
22:55:32 at Function.Module._load (internal/modules/cjs/loader.js:529:3)
22:55:32 at Module.require (internal/modules/cjs/loader.js:636:17)
22:55:32 at require (internal/modules/cjs/helpers.js:20:18)
22:55:32 info Run CLI with --verbose flag for more details.
22:55:33





"名称": "", “版本”:“0.0.1”, “私人”:真的, “脚本”: "android": "react-native run-android", "android-qa1": "gulp set --env=qa1 && react-native run-android", "android-qa2": "gulp set --env=qa2 && react-native run-android", "android-qa3": "gulp set --env=qa3 && react-native run-android", "android-production": "gulp set --env=production && react-native run-android", "android-local": "gulp set --env=local && react-native run-android", "ios": "react-native run-ios", "start": "react-native start", “测试”:“开玩笑”, "lint": "eslint.", “安装后”:“补丁包” , “依赖”: "@freakycoder/react-native-helpers": "^0.1.3", "@react-native-community/async-storage": "^1.11.0", "@react-native-community/剪贴板": "^1.2.2", "@react-native-community/masked-view": "^0.1.10", "@react-native-community/push-notification-ios": "^1.7.3", "@react-native-community/toolbar-android": "git+https://github.com/react-native-toolbar-android/toolbar-android.git#master", "@react-native-picker/picker": "^2.0.0", "@react-navigation/drawer": "^5.8.2", "@react-navigation/路由器": "^5.4.7", "@react-navigation/stack": "^5.5.1", "@sentry/react-native": "^2.3.0", "axios": "^0.19.2", "babel-preset-react-native": "^4.0.1", "吞咽": "^4.0.2", "gulp-clean": "^0.4.0", "gulp-rename": "^2.0.0", "lodash": "^4.17.20", “主”:“^1000.0.1”, "路径": "^0.12.7", “更漂亮”:“^2.3.2”, “反应”:“17.0.2”, “反应原生”:“0.65.1”, "react-native-camera": "^3.42.0", "react-native-charts-wrapper": "^0.5.7", “反应原生配置”:“^1.3.1”, "react-native-copilot": "^2.5.1", "react-native-crypto": "^2.2.0", "react-native-datepicker": "^1.7.2", "react-native-default-preference": "^1.4.3", "react-native-dotenv": "^0.2.0", "react-native-dynamic-vector-icons": "^0.1.1", “反应原生元素”:“^3.4.2”, "react-native-fast-image": "^8.3.2", "react-native-geolocation-service": "^5.2.0", "react-native-get-random-values": "^1.4.0", "react-native-image-slider-box": "^1.1.5", “react-native-improved-text-input”:“0.0.1”, "react-native-inappbrowser-reborn": "^3.4.0", “反应原生地图”:“^0.27.1”, “反应原生模式”:“^11.5.6”, "react-native-permissions": "^3.0.0", "react-native-push-notification": "^6.1.3", "react-native-qrcode-scanner": "^1.5.3", "react-native-reanimated": "^1.9.0", "react-native-safe-area-context": "^0.7.3", “反应原生屏幕”:“^2.8.0”, "react-native-shared-preferences": "^1.0.2", "react-native-snap-carousel": "^3.9.1", "react-native-spinkit": "^1.5.0", "react-native-splash-screen": "^3.2.0", "react-native-svg": "^12.1.0", "react-native-swipe-gestures": "git+https://github.com/wymsee/react-native-swipe-gestures.git#master", "react-native-tracking-transparency": "^0.1.0", "react-native-vector-icons": "^8.1.0", "react-native-webview": "^9.4.0", “uuid”:“^7.0.3” , “开发依赖”: "@babel/core": "^7.12.9", "@babel/runtime": "^7.12.5", "@react-native-community/eslint-config": "^2.0.0", "@react-navigation/native": "^5.5.1", "babel-jest": "^26.6.3", "eslint": "^7.14.0", "笑话": "^26.6.3", "metro-react-native-babel-preset": "^0.66.0", "react-native-codegen": "^0.0.7", "补丁包": "^6.4.7", "平台": "^1.3.5", “道具类型”:“^15.7.2”, "react-native-gesture-handler": "^1.6.1", “反应测试渲染器”:“17.0.2”, “shelljs”:“^0.8.4” , “开玩笑”: “预设”:“反应原生”

【问题讨论】:

【参考方案1】:

我在将 RN 升级到 65.1 后遇到了这个问题。根据我的调查,这是由“Bundle React Native 代码和图像”构建阶段使用的不正确的 Node.js 版本引起的。我可以确认该错误Node v14.17.6 没有发生

如果您使用 NVM,请尝试在 XCode “构建阶段” 选项卡中添加以下行 => “捆绑 React Native 代码和图像”node_modules/react-native/scripts/react-native-xcode.sh 脚本调用之前加载 NVM 的部分:

[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh # This loads NVM

我能够以这种方式解决问题。

否则,如果您不使用 NVM,您仍然可以根据需要覆盖/硬编码节点二进制文件,即:

export NODE_BINARY=~/.nvm/versions/node/v14.17.6/bin/node

它应该可以解决问题。

【讨论】:

以上是关于error Unexpected token = 从 RN 0.64.2 升级到 0.65.1 之后的主要内容,如果未能解决你的问题,请参考以下文章

Parsing error: Unexpected token : (或=或<)

执行shell脚本报错:syntax error near unexpected token `或syntax error: unexpected end of file

shell出现syntax error near unexpected token `<' 解决方法

elasticsearch启动报错 syntax error near unexpected token `<'

如何解决syntax error near unexpected token `fi'

[eslint]报错:Vue eslint Parsing error: Unexpected token