SyntaxError:严格模式不允许在新创建的应用程序的词法嵌套语句中进行函数声明 [英] SyntaxError: Strict mode does not allow function declarations in a lexically nested statement on a newly created app
问题描述
我今天遇到这个错误,然后我卸载react-native-cli并重新安装它,问题仍然存在.我什至运行了 reset-cache 命令!我尝试创建一个新的 react-native 应用程序,但仍然看到错误.我不想为此重新安装我的操作系统...
I got this error today, then I uninstall react-native-cli and reinstall it, the problem's still there. I even run the reset-cache command! I tried to create a new react-native app and still see the error. I don't want to reinstall my os for this...
推荐答案
我也遇到过这个问题发生这种情况是因为 babel 现在自动添加了使用严格"所以它检查词法嵌套语句中的函数声明
I've faced this issue too this happened because babel now adds 'use strict' automatically so it checks function declarations in a lexically nested statement
这发生在核心 react-native 代码中 (node_modules\react-native\ReactAndroid\src\androidTest\assets\AndroidTestBundle.js)您可以在 github 问题 https://github.com/facebook/react-native 中找到更多信息/issues/11389
this happens in core react-native code (node_modules\react-native\ReactAndroid\src\androidTest\assets\AndroidTestBundle.js) you can find more info in github issue https://github.com/facebook/react-native/issues/11389
作为一种解决方法,您可以启用远程调试 - 它对我有用
as a workaround you can enable remote debugging - it works for me
我找到了简单的解决方案
I've found simple solution
打开 node_modules\react-native\Libraries\Core\InitializeCore.js 第 112 行
open node_modules\react-native\Libraries\Core\InitializeCore.js line 112
将函数 handleError(e, isFatal) 改为 var handleError = function(e, isFatal)
change function handleError(e, isFatal) to var handleError = function(e, isFatal)
然后做 npm start -- --reset-cache
then do npm start -- --reset-cache
你也可以在上面的github issue中查看
you can also check it in github issue above
这篇关于SyntaxError:严格模式不允许在新创建的应用程序的词法嵌套语句中进行函数声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!