react-native: SyntaxError: Strict mode does not allow function declarations in a lexically nested statement on a newly created app
It worked untill yesterday
I tried all these things: Remove nodejs, reinstall react-native-cli, run npm start – --reset-cache. wipe my android emulator data.
I asked the question on stackoverflow but it’s look like that no one have interested in it…
This’s really annoying, I can see that someone also has the same problem with me.
Windows 10 64bit. Latest react-native-cli. Newly created app without any modification. Nodejs 7.2.1
npm-debug
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Users\\lednh\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start',
1 verbose cli '--',
1 verbose cli '--reset-cache' ]
2 info using npm@4.0.5
3 info using node@v7.2.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle ReactTodosApp@0.0.1~prestart: ReactTodosApp@0.0.1
6 silly lifecycle ReactTodosApp@0.0.1~prestart: no script for prestart, continuing
7 info lifecycle ReactTodosApp@0.0.1~start: ReactTodosApp@0.0.1
8 verbose lifecycle ReactTodosApp@0.0.1~start: unsafe-perm in lifecycle true
9 verbose lifecycle ReactTodosApp@0.0.1~start: PATH: C:\Users\lednh\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin;C:\Users\lednh\Documents\react-native\ReactTodosApp\node_modules\.bin;C:\flow;c:\program files (x86)\graphicsmagick-1.3.25-q16;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\Java\jdk1.8.0_112\bin;C:\Users\lednh\AppData\Local\Android\sdk\platform-tools;C:\Users\lednh\AppData\Local\Android\sdk\tools;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Python27\python.exe;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Yarn\bin;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Program Files\dotnet\;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\nodejs\;C:\Program Files\MongoDB\Server\3.4\bin;C:\Users\lednh\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Users\lednh\AppData\Local\.meteor\;C:\Python27\python.exe;C:\Users\lednh\AppData\Local\Yarn\.bin;C:\Users\lednh\AppData\Roaming\Composer\vendor\bin;C:\Users\lednh\AppData\Roaming\npm
10 verbose lifecycle ReactTodosApp@0.0.1~start: CWD: C:\Users\lednh\Documents\react-native\ReactTodosApp
11 silly lifecycle ReactTodosApp@0.0.1~start: Args: [ '/d /s /c',
11 silly lifecycle 'node node_modules/react-native/local-cli/cli.js start "--reset-cache"' ]
12 silly lifecycle ReactTodosApp@0.0.1~start: Returned: code: 3221225786 signal: null
13 info lifecycle ReactTodosApp@0.0.1~start: Failed to exec start script
14 verbose stack Error: ReactTodosApp@0.0.1 start: `node node_modules/react-native/local-cli/cli.js start "--reset-cache"`
14 verbose stack Exit status 3221225786
14 verbose stack at EventEmitter.<anonymous> (C:\Users\lednh\AppData\Roaming\npm\node_modules\npm\lib\utils\lifecycle.js:279:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (C:\Users\lednh\AppData\Roaming\npm\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:885:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid ReactTodosApp@0.0.1
16 verbose cwd C:\Users\lednh\Documents\react-native\ReactTodosApp
17 error Windows_NT 10.0.14393
18 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\lednh\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start" "--" "--reset-cache"
19 error node v7.2.1
20 error npm v4.0.5
21 error code ELIFECYCLE
22 error ReactTodosApp@0.0.1 start: `node node_modules/react-native/local-cli/cli.js start "--reset-cache"`
22 error Exit status 3221225786
23 error Failed at the ReactTodosApp@0.0.1 start script 'node node_modules/react-native/local-cli/cli.js start "--reset-cache"'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the ReactTodosApp package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error node node_modules/react-native/local-cli/cli.js start "--reset-cache"
23 error You can get information on how to open an issue for this project with:
23 error npm bugs ReactTodosApp
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls ReactTodosApp
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
After a while searching on google, I can see that many people are facing this problems and there are no proper fix for this…
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 46
- Comments: 90 (10 by maintainers)
Commits related to this issue
- Patch for issue https://github.com/facebook/react-native/issues/11389 — committed to Mille-Volts/react-native by nmorel 7 years ago
- fix nested "Strict mode does not allow function declarations in a lexically nested statement on a newly created app" error on android builds after babel upgrade... https://github.com/facebook/react-na... — committed to irvingdp/react-native by deleted user 7 years ago
- Revert "fix nested "Strict mode does not allow function declarations in a lexically nested statement on a newly created app" error on android builds after babel upgrade... https://github.com/facebook/... — committed to irvingdp/react-native by deleted user 7 years ago
- fix nested "Strict mode does not allow function declarations in a lexically nested statement on a newly created app" error on android builds after babel upgrade... https://github.com/facebook/react-na... — committed to irvingdp/react-native by deleted user 7 years ago
- fix nested "Strict mode does not allow function declarations in a lexically nested statement on a newly created app" error on android builds after babel upgrade... https://github.com/facebook/react-na... — committed to irvingdp/react-native by deleted user 7 years ago
I’ve found how to fix it
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
hope that it will be fixed soon I have created pull request for that https://github.com/facebook/react-native/pull/11390
and for me it works without any error if remote debugging is enabled
If you make a search, you can see that many many people have the exact same problem and many of they change the pc, or reinstall their OS to make rn work again.
Running React-native 0.35 and having same issue – this is what helped to me
In node_modules/react-native/Libraries/BatchedBridge/BatchedBridgedModules/NativeModules.js
function normalizePrefix(moduleName: string) ...
REPLACE WITH:
const normalizePrefix = function(moduleName: string)
In /node_modules/react-native/Libraries/Utilities/UIManager.js:
function normalizePrefix(moduleName: string) ...
REPLACE WITH:
const normalizePrefix = function(moduleName: string)
In /node_modules/react-native/…/InitializeJavascriptAppEngine.js:
function handleError(e, isFatal) ...
REPLACE WITH:
var handleError = function(e, isFatal)
then do npm start – --reset-cache
@lohithananda On the android emulator, press Ctrl+M to open the dev menu, and then choose start Rote JS Debugging, it will open a new tab in chrome, keep it open.
Shipped to 0.39.2.
Fuck my life
@LitbLeo looks like this code is in another place in 0.34.1 try to open node_modules\react-native\Libraries\JavaScriptAppEngine\Initialization\InitializeJavaScriptAppEngine.js line 120 and change function handleError(e, isFatal) to var handleError = function(e, isFatal) then do npm start – --reset-cache
I can’t find node_modules\react-native\Libraries\Core\InitializeCore.js,Whta to do? @ @Taximan @
You can revert update to RN v0.39 also … v0.38 works nice 😃
Another way to “fix” this, if you can’t update to a newer version yet, is to enable JS Minify mode in Dev Settings. Works on version 0.34.0.
I see the same and only for Android version. When debug is enabled everything works.
I’ve tried to understand the cause of the problem, jumping from commit to commit back in history and it looks like the reason of problem is the latest release of babel. https://github.com/babel/babel/releases/tag/v6.20.0
With babel 6.18.0 in yarn.lock file everything is okay. When I remove yarn.lock and install it again one of sub-dependencies fetches the latest version of babel and the problem appears.
my react-native version is “0.31.0”。set emulator dubug js remote works,but my emulator runs slowly.I’m finding another way to save it. God bless me.
Me too, same error. Nothing of the previous suggested methods work, even if i am able to execute the app if remote js debug is active
+1
For everyone who still facing this error try another workaround. Edit node_modules/react-native/Libraries/Utilities/UIManager.js file and replace:
function normalizePrefix(moduleName: string): string {
withvar normalizePrefix = function (moduleName: string): string {
This worked for me, referencing superfe issue
This is occurring in 0.46.4.
07-31 00:07:35.786 4831-5376/com.nycevents E/ReactNativeJNI: Got JS Exception: SyntaxError: Strict mode does not allow function declarations in a lexically nested statement. (http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:1583) 07-31 00:07:35.786 4831-5376/com.nycevents E/unknown:React: Exception in native call from JS com.facebook.react.devsupport.JSException: SyntaxError: Strict mode does not allow function declarations in a lexically nested statement. (http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:1583) at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:148) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194) at java.lang.Thread.run(Thread.java:818) Caused by: com.facebook.jni.CppException: SyntaxError: Strict mode does not allow function declarations in a lexically nested statement. (http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:1583) at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:148) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194) at java.lang.Thread.run(Thread.java:818) 07-31 00:07:35.788 4831-5376/com.nycevents E/unknown:React: Exception in native call java.lang.RuntimeException: Error calling AppRegistry.runApplication at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:148) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194) at java.lang.Thread.run(Thread.java:818) Caused by: com.facebook.jni.CppException: Could not get BatchedBridge, make sure your bundle is packaged correctly at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:148) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194) at java.lang.Thread.run(Thread.java:818)
Just activate a JS Minify option in the Emulator Dev Settings
Here it worked only with this, I hope it has helped;)
Same happens in
v0.46.1
Hey, guys, I found the same issue on RN
45.1
install on ios9.3
. But it works fine on ios10.3
If there has anyone get into this problem?I have an app which till yesterday was working properly and i have to implement new plugin so i switched to different branch on my git flow and installed that plugin, but i had got to make build for client it was the urgent requirement so i switched back to develop branch and removed node_modules folder and did NPM install but after that i started getting following issue:SyntaxError: Strict mode does not allow function declarations in a lexically nested statement I checked the work around solution you provided about opening node_modules\react-native\Libraries\Core\InitializeCore.js line 112 and making required changes. but in my react-native\Libraries\ folder in node_modules i am not able to see Core folder nor am i able to find InitializeCore.js in whole react-native folder.
Following are my versions of react & react-native mentioned in package.json: “react”: “15.3.1”, “react-native”: “0.34.1”,
And the application has to be uploaded to play store in next 2 days. So i am not in a position to upgrade react-native version also.
Please suggest some solution. Stuck badly.
@karpoff I did that still I’m getting the same error But if I run using debug js remotely it works fine. But I had to create offline app for testing multiple devices as well as putting it in app store. using:
"native-base": "0.5.15", "react": "15.3.1", "react-native": "0.33.1",
🥇 Fixed on React Native 0.40.0
“react”: “15.3.1”, “react-native”: “^0.34.1”, in node_modules/react-native/Libraries/Utilities/UIManager.js remove ‘use strict’;
add gulp task
and postinstall in package.json 's scripts
Updated react-native to version 0.47.0 and it fixed it.
I’m facing the same issue @jrempel1. Any fix?
NOTE: This problem occurs just in Android.
I’ve just disabled “JS Dev Mode” and enabled “JS Minify”. It seems to work…
For the lazy:
@quietbits Thanks,this way can fix this issue!
@taozijie @Taximan Me too,what to do?My version is 0.34.1
Works fine on with react-native version 0.39.2.
@karpoff Hi, I’m having trouble locating the file. I do not have the Libraries folder at all under …/npm/node-modules/react-native-cli…there’s another node-modules folder in it which doesn’t have the Libraries folder either
@lednhatkhanh i am working on the real android device
@niranjan-b-prajapati update react and react-native to “react”: “~15.4.0”, “react-native”: “^0.41.2” Delete node-modules of your project and install npm. For me it works.
I think you might have to do
npm upgrade
, but that would upgrade all of your node modules, not just react native. Otherwise I would just do Karpoff’s solution. It’s the 5th response from the top.Edit According to the docs https://facebook.github.io/react-native/releases/0.28/docs/upgrading.html
react-native upgrade
should work. I don’t know why it wouldn’t when you ran it.This bug has been fixed. If you
react-native init
a new project now, you will see that this code/bug has been changed.Argh! My bad! Thanks @EQuimper
I’ve been running a day running my first application and I can not believe the mistake was this …
It works for me too…
Thanks @karpoff
Issue exists on react native v0.39.1 Solution suggested by @karpoff works Thank you so much