-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SyntaxError: Strict mode does not allow function declarations in a lexically nested statement on a newly created app #11389
Comments
same here, worked yesterday, started a new project this morning and got this very same error. |
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. |
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. |
@suevalov Can you please tell me how to lock the babel version to 6.18? Thank you. |
I've found how to fix it open node_modules\react-native\Libraries\Core\InitializeCore.js line 112 hope that it will be fixed soon and for me it works without any error if remote debugging is enabled |
is this issue still happening right now? |
@karpoff your solution works for me too. Thanks! Hope it will be fixed soon |
I am new to react native but i am getting the red screen with syntaxError:SyntaxError: Strict mode does not allow function declarations in a lexically nested statement. any one please help. @karpoff how we can enable remote debugging for android device |
@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. |
@lednhatkhanh i am working on the real android device |
@lohithananda enabling dev menu on real device is performed by shaking phone in your hand. on some devices soft menu button is available (it looks like hamburger button on my phone) |
You can revert update to RN v0.39 also ... v0.38 works nice :) |
Thank u soo much:)@ColCh |
Issue exists on react native v0.39.1 |
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 |
Thank u soo much:)@ColCh |
@karpoff Thank you :) |
@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 |
@pratik151192 this is not in the react-native-cli this is under the node_modules/react-native/ inside you project |
Argh! My bad! Thanks @EQuimper |
The reason this fails on Android is because RN uses an ancient version of JSC which does not support lexical function declarations. There is a babel plugin that fixes this (since updating JSC is a big project #10245) https://babeljs.io/docs/plugins/transform-es2015-block-scoping/ Can we add this plugin to the current babel preset? |
@arv While I add {
"presets": ["react-native"],
"plugins": ["transform-es2015-block-scoping"]
} Issue still exists |
Please fix this issue and update react @facebook-github-bot |
Hope this gets merged soon. Lot of applications are failing after update. |
+1 |
1 similar comment
+1 |
I also have same problem. Did it fixed? |
+1 |
+1 "react-native": "0.38" works fine |
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. |
thx to @niranjan-b-prajapati ,I change my react version to v15.4.0 , my react-native to 0.41.2. It works to me |
Had the same exact issue out of blue sky with RN |
For the lazy:
|
@dmueller39 it works, do u know what caused it? |
This is problem in a Network! Active mode Remote JS Debuggin in APP! |
Just activate a JS Minify option in the Emulator Dev Settings
Here it worked only with this, I hope it has helped;) |
Hey, guys, I found the same issue on RN |
Same happens in |
Fuck my life |
This is occurring in 0.46.4.
|
Updated react-native to version 0.47.0 and it fixed it. |
I am seeing this issue in 0.47.0 and 0.47.1 on Android. The error seems to be occurring where the function 'use strict';
if (process.env.NODE_ENV !== "production") {
'use strict';
...
function warnNoop(publicInstance, callerName) {
{
var constructor = publicInstance.constructor;
warning(false, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op.\n\nPlease check the code for the %s component.', callerName, callerName, constructor && (constructor.displayName || constructor.name) || 'ReactClass');
}
} This part of the bundle seems to come from this React file. It looks like Babel is inserting the first I'm not really sure how to fix this cleanly. I'm not sure how the module got wrapped in the conditional, and whether the right solution is to update the code generating the conditional, or to change the function declaration to a lambda in React. The suggestion above of turning on minification seems pretty hacky, especially since it will pop up an error unless you also disable debug mode (which is annoying for me since my code looks at I found this StackOverflow question with suggestions on how to stop Babel from injecting the I ended up settling on |
I was able to resolve with:
|
The below combo seems to fix the issue:
or
|
hey @arsenslyusarchuk thanks a lot! your hack saved my day. Can you explain how did you come to that solution? |
Same failure on ios8 with combination:
Any solution for this? |
Same for the
after upgrade from the 46.3 version. |
I got it working by using this plugin: https://www.npmjs.com/package/babel-plugin-transform-strict-mode For me, the issue was that 'use strict' was not enabled by babel (suddenly). |
"react": "15.3.1", add gulp task
and postinstall in package.json 's scripts
|
Hello: with a .babelrc using that plugin you mentioned @marcianoviereck :
and I have the problem when Remote Debug JS is off. Works ok when Remote JS is on. Anyone else? Thank you! |
For all who want to solve problem. Mb u want to add babel plugin which add "use strict" to all files just delete it.
|
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
After a while searching on google, I can see that many people are facing this problems and there are no proper fix for this...
The text was updated successfully, but these errors were encountered: