Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: Strict mode does not allow function declarations in a lexically nested statement on a newly created app

Tags:

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...

like image 541
Le Dinh Nhat Khanh Avatar asked Dec 09 '16 10:12

Le Dinh Nhat Khanh


1 Answers

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

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

open node_modules\react-native\Libraries\Core\InitializeCore.js line 112

change function handleError(e, isFatal) to var handleError = function(e, isFatal)

then do npm start -- --reset-cache

you can also check it in github issue above

like image 67
Anton Karpov Avatar answered Oct 31 '22 19:10

Anton Karpov