reactjs 从RN 0.64.2升级到0.65.1后出现意外标记=错误

m1m5dgzv  于 2022-11-04  发布在  React
关注(0)|答案(1)|浏览(112)

我刚刚通过升级助手从64.1升级到65.1。
但我开始得到这个错误,并没有能够修复它。
我已经将node/npm升级到14.17,并且做了我能想到的所有其他事情。有人能帮忙吗?
此错误发生在生成过程中。

SyntaxError: Unexpected token =

22:55:32 > Task :react-native-community_masked-view:compileReleaseLibraryResources
22:55:32
22:55:32 > Task :app:bundleReleaseJsAndAssets FAILED
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
{
"name": "",
"version": "0.0.1",
"private": true,
"scripts": {
"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",
"test": "jest",
"lint": "eslint .",
"postinstall": "patch-package"
},
"dependencies": {
"@freakycoder/react-native-helpers": "^0.1.3",
"@react-native-community/async-storage": "^1.11.0",
"@react-native-community/clipboard": "^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/routers": "^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",
"gulp": "^4.0.2",
"gulp-clean": "^0.4.0",
"gulp-rename": "^2.0.0",
"lodash": "^4.17.20",
"main": "^1000.0.1",
"path": "^0.12.7",
"prettier": "^2.3.2",
"react": "17.0.2",
"react-native": "0.65.1",
"react-native-camera": "^3.42.0",
"react-native-charts-wrapper": "^0.5.7",
"react-native-config": "^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",
"react-native-elements": "^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",
"react-native-maps": "^0.27.1",
"react-native-modal": "^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",
"react-native-screens": "^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"
},
"devDependencies": {
"@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",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.66.0",
"react-native-codegen": "^0.0.7",
"patch-package": "^6.4.7",
"platform": "^1.3.5",
"prop-types": "^15.7.2",
"react-native-gesture-handler": "^1.6.1",
"react-test-renderer": "17.0.2",
"shelljs": "^0.8.4"
},
"jest": {
"preset": "react-native"
}
}
e5nszbig

e5nszbig1#

我在将RN升级到65.1后遇到了这个问题。根据我的调查,这是由于在“Bundle React Native code and images”构建阶段使用了不正确的Node.js版本所致。我可以确认该错误不会发生在Node v14.17.6上。

如果您使用NVM,请尝试在XCode “Build phases” tab =〉“Bundle React Native code and images” 部分中添加以下行,以便在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

应该可以了。

相关问题