ReactNative - 未处理的 JS 异常:SyntaxError

Posted

技术标签:

【中文标题】ReactNative - 未处理的 JS 异常:SyntaxError【英文标题】:ReactNative - Unhandled JS Exception: SyntaxError 【发布时间】:2016-12-07 15:53:58 【问题描述】:

当我尝试在 ios 8 上启动我的 RN 应用程序时,我收到了这个奇怪的错误:Unhandled JS Exception: SyntaxError 仅此而已,没有更多信息了。 有没有人偶然发现了这个问题? 在 iOs 9+ 上,应用程序运行正常。

xCode 版本:8.1。来自 xCode 的日志:2016-12-07 16:33:57.073 [info][tid:main][RCTBatchedBridge.m:73] Initializing <RCTBatchedBridge: 0x7fc36c72ae80> (parent: <RCTBridge: 0x7fc36c060920>, executor: RCTJSCExecutor) 2016-12-07 16:34:29.369 [warn][tid:com.facebook.react.javascript][RCTBatchedBridge.m:509] Failed to execute source code: Unhandled JS Exception: SyntaxError 2016-12-07 16:34:29.369 [fatal][tid:main] Unhandled JS Exception: SyntaxError

我的 package.json: "name": "...", "version": "0.0.1", "private": true, "scripts": "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" , "dependencies": "fbjs": "^0.8.6", "moment": "^2.16.0", "react": "15.3.2", "react-native": "^0.37.0", "react-native-chart": "^1.0.8-beta", "react-native-gifted-chat": "0.0.10", "react-native-image-picker": "^0.23.0", "react-native-image-progress": "^0.6.0", "react-native-locale": "0.0.11", "react-native-material-kit": "^0.3.3", "react-native-message-bar": "^1.6.0", "react-native-modal-datetime-picker": "^3.0.0", "react-native-modal-picker": "0.0.16", "react-native-router-flux": "^3.37.0", "react-native-timer": "^1.1.2", "shortid": "^2.2.6" , "jest": "preset": "jest-react-native" , "devDependencies": "babel-jest": "17.0.0", "babel-preset-react-native": "1.9.0", "jest": "17.0.1", "jest-react-native": "17.0.1", "react-test-renderer": "15.3.2", "whatwg-fetch": "1.0.0"

Node、npm 和 react-native 版本:adamt@Dev-2 ~/D/G/myApp> npm -v 4.0.2 adamt@Dev-2 ~/D/G/myApp> node -v v4.4.4 adamt@Dev-2 ~/D/G/myApp> react-native -v react-native-cli: 1.2.0 react-native: 0.37.0

非常欢迎任何有关此错误发生原因的帮助!

【问题讨论】:

【参考方案1】:

React Native 0.39 版存在问题。

您需要在 node_modeles/react-native/Libraries/Core/InitializeCore.js 的第 30 行注释掉 'use strict';

// 'use strict'; Fix to RN 0.39 - https://github.com/facebook/react-native/issues/11389

或者,您可以返回到 React Native 0.38 版。

【讨论】:

以上是关于ReactNative - 未处理的 JS 异常:SyntaxError的主要内容,如果未能解决你的问题,请参考以下文章

未处理的 JS 异常:找不到变量:进程

在使用 React Native 的 IOS 运行时出现“未处理的 JS 异常:本机模块不能为空”错误

模块 AppRegistry 不是注册的可调用模块

未处理的 JS 异常:找不到变量:需要

没有堆栈',原因:'未处理的 JS 异常:无效的正则表达式:无效的组说明符名称

ReactNative JS 文本未更新