react-native: Unhandled JS Exception: TypeError: undefined is not an object (evaluating 'this._subscribableSubscriptions.forEach')
When changing scheme to Release in able to run the app on the device, it triggered an error
Unhandled JS Exception: TypeError: undefined is not an object (evaluating 'this._subscribableSubscriptions.forEach')
This crashed the application.
I searched for the error code and found it: project/node_modules/react-native/Libraries/Components/Subscribable.js
on line 33 with RN 0.51.0
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 42
- Comments: 75 (13 by maintainers)
Commits related to this issue
- [WORKAROUND] https://github.com/facebook/react-native/issues/17348 — committed to brainbeanapps/react-native by alexey-pelykh 7 years ago
- Hot fix from: https://github.com/facebook/react-native/issues/17348 — committed to vovkasm/react-native by vovkasm 7 years ago
- Fix for 17348 Fixes https://github.com/facebook/react-native/issues/17348 - Unhandled JS Exception: TypeError: undefined is not an object (evaluating 'this._subscribableSubscriptions.forEach') — committed to iMagdy/react-native by iMagdy 6 years ago
- fixes callstack described in #17348 — committed to arichnad/react-native by arichnad 6 years ago
- Add metro-bundler to dependencies This fixes the RN issues @ https://github.com/facebook/react-native/issues/17348 — committed to hush2/gma-news-unofficial by hush2 7 years ago
I fixed it by evaluating variable
this._subscribableSubscriptions
on line 33 on react native fileproject/node_modules/react-native/Libraries/Components/Subscribable.js
Changing this:
To this:
The issue is caused by the uglify-es@3.3.2,back to 3.2.2
npm install -save uglify-es@3.2.2
@facebook-github-bot no-template
Hey @a3diti, thanks for posting this! It looks like your issue is missing some required information. Can you please add all the details specified in the Issue Template? This is necessary for people to be able to understand and reproduce your issue. I am going to close this, but please feel free to open a new issue with the additional information provided. Thanks!
How to Contribute • What to Expect from Maintainers
This bug should be caused by
uglify-es
3.3.X. I confirm that it’s fixed by downgradinguglify-es
. Just add this block topackage.json
:The
_subscribableSubscriptions
workaround is no longer necessary after downgradinguglify-es
.For people using Expo, you don’t need to edit anything in react-native. I confirm that adding
"resolutions": { "uglify-es": "3.2.2" }
to
package.json
does indeed fix the problem.Tried both publishing on Expo and building a standalone app and it’s working like a charm
I am closing the issue I created today for this one. Here is what I contributed on it.
Is this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment:
OS: Windows 10
Node: 8.9.1
Yarn: 1.3.2
npm: 5.5.1
Watchman: Not Found
Xcode: N/A
Android Studio: Version 3.0.0.0 AI-171.4408382
Packages: (wanted => installed)
react: 16.0.0 => 16.0.0
react-native: 0.51.0 => 0.51.0
Steps to Reproduce
Expected Behavior
I expected that the release version would work as the debug version did.
Actual Behavior
Signed apk crashes when any screen which has any version of ScrollView in it’s render.
The problem is this:
this._subscribableSubscriptions.forEach
fails because the “this._subscribableSubscriptions” is null (and should not be).Here is where the error occurs: in Subscribable.js (…\node_modules\react-native\Libraries\Components\Subscribable.js)
This is the original code.
Here is where i removed the failing call. I have confirmed that this._subscribableSubscriptions returns a null and crashes when the forEach() is called.
Following removing the offending code, the app no longer crashes on startup.
FROM LOGCAT:
Reproducible Demo
Because the app crashes on a production build here is a simple App.js file.
This demo can be reproduced by:
NOTE: but probably not important. When I build my app (either my own app or the test app), I must run gradlew assembleRelease twice, it always fails the first time. I think it needs to reset the transform cache.
ADDITIONAL NOTE: From what the other person who has seen this said, when reducing the version of React-native to 49.5 the problem goes away.
I have this error when building APK via Expo. RN 0.51.0
@facebook-github-bot reopen please. It’s the same issue for me. No addition information. Just started to throw this error today without any changes.
Related to ScrollView. It appears on any View containing ScrollView inside like FlatList.
@googya Not sure about concrete uglify-es versions, but it looks ulify-es related. Why?
We did not try to deeply investigate packing process, because fork/patch RN was more fast and logical fix for us, but I probably can diff bundled js from jenkins builds and local (if it is really needed).
uglify-es@3.2.2
is the only stable resolution that worked for me so far, any new version breaks the app somewhere, up to@3.3.7
.@a3diti Shouldn’t this be fixed in react-native and * * NOT * * as a manually added resolution in a developer’s project’s package.json?
Concerns:
Requiring the addition of an uglify-es resolution to your Awesome project’s package.json is * NOT * a fix. It feels like a temporary work-around for the root problem.
Question: How will a developer know he needs to add an uglify-es resolution to his Awesome project’s package.json ??? ( Changing react-native init to add the uglify-es resolution seems silly. )
Work-Around:
I confirmed the uglify-es resolution work-around works on both Android and iOS release builds.
Build and run:
got it work, for node people make sure the uglify-es module version is set specifically to 3.2.2.
"uglify-es": "3.2.2"
I had
"uglify-es": "^3.2.2"
before and it would fail"resolutions": { "uglify-es": "3.2.2" }
fixed the issue that was introduced by the first solutionthis._subscribableSubscriptions &&
for me.@ohflying how did you find the fact of being caused by uglify-es ?
same issue for me. debug build works fine, but fail in release build. RN 0.51.0
React Native version 0.50.3 is affected too
This comment https://github.com/facebook/react-native/issues/17348#issuecomment-353892314 fixed it for me.
Thanks @a3diti !
I’ve submitted a PR (https://github.com/facebook/react-native/pull/17463) with this fix. Hopefully it gets merged soon.
@esutton Ok, i guess you have a different environment since the
uglify-es
solution didn’t work for you.I recommend some necessary actions to perform when installing
uglify-es
, i do those sometimes when i have unexplainable errors:node_modules
folder, removepackage-lock.json
file, re-install packages using yarn, not npm 5.x because v5.x is known to have some bugs.When i test the app for release, on Xcode i go to “Edit Scheme”>Run>Build Configuration>Release Also i test it on TestFlight on some devices before releasing it.
If those solutions don’t work for you, try to initiate a new project on another folder and edit
package.json
accordingly, and thenyarn install
in order to install anything that is changed on package.json. Then copy all js/assets you had on the last project, don’t forget toreact-native link
if you have any installed component that requires it.I am seeing this even with uglify-es set to 3.3.4 or 3.2.2. Only on release builds but not in debug.
For those who have initiated the project and have already uglify-es version 3.3.2 please update to higher version. For new created projects the problem is fixed automatically because current version of uglify is v3.3.4. The problem It was caused with the app crashing when installing the app as release on the simulator or device from component of react-native located in:
Libraries/Components/Subscribable.js
. It seemed thecomponentWillUnmount
was called beforecomponentWillMount
and generating an error for an undefined variable, this kind of problem is believed to be generated from uglify-es v3.3.2 and fixed by uglify-es v3.3.4, some kind of bug during compression of js files, probably on rare occasions (when RN project is build with release mode it is compressed by default using uglify-es).Solution Note: For projects initiated with uglify-es v3.3.2 and probably lower versions
resolutions
part topackage.json
for your project in order to get v3.3.4 or higher of uglify-es:npm install
oryarn install
to install the node packagesExample of package.json Done I’m closing the issue since it is automatically resolved.
EDIT
It seems the issue still persist on some users on different environment, i was mistaken to close the issue!
Had the same issue and only @pavlomakarov solution worked for me (
"metro-bundler": "0.22.1"
to my dependencies).Deeply troubling that a minification pass causes this type of logic issue, as the implications for the rest of the app are unknown but also possible unstabilizing. JS stacks feel like such a house of cards sometimes…
does not work for me as well
This issue seems to only occur in minified code. Upgrading metro-bundler to the latest version resolved it for me. You can just explicitly add it to your dependencies, I’m using
metro-bundler
0.22.1. Also, addinguglyfy-es@3.2.2
to resolutions didn’t help, because older versions of metro bundler still forced a 3.3.2 dependencyWe can resolve the issue by checking this._subscribableSubscriptions on line 33 on react native file project/node_modules/react-native/Libraries/Components/Subscribable.js - line 33
(-)this._subscribableSubscriptions.forEach (+)this._subscribableSubscriptions && this._subscribableSubscriptions.forEach(
@jnrepo 's solution worked for me, thanks a lot !
But it worked once I deleted the
node_modules
folder but also thepackage-lock.json
file. So if it’s still not working for you, try addinguglify
as a dependency:npm install --save uglify-es@3.2.2
Change your
package.json
:From
"uglify-es": "^3.2.2"
to"uglify-es": "3.2.2"
And then run:
rm -rf node_modules/ package-lock.json && npm i
+1 for
npm install -save uglify-es@3.2.2
; No need to mess with resolutions. Deletenode_modules/
, run that line, re-runnpm i
, and publish. Works beautifully. Thanks @ohflying!uglify-es or uglify-js? Because uglify-es didn’t help me…
On Thu, Dec 28, 2017 at 1:51 PM pavlomakarov notifications@github.com wrote:
downgrade
gulify-es
worked for me.it seems that
gulify-es
has cause quite a few issues (#16745) It also seems thatreact-native
doesn’t have smoke test? or integration test (release version)Running into same issue only on release not debug. RN 0.51
@sonaye thanks! I’m using expo 24 and your comment worked for me. I had to do both your steps. https://github.com/facebook/react-native/issues/17348#issuecomment-354209083
has anyone posted an issue on
uglify-es
?I just created a brand new project with react-native-cli 2.0.1 (the latest version as I write this) and once I’d added my dependencies (
native-base
andreact-navigation
) I saw that the installed version ofuglify-es
was already set at3.3.4
without me having to modify it.I was able then to install a Release version of my app directly to my iPhone without incurring the crash.
So issue solved, for new projects at least?
Also looks like adding a dependency to
"uglify-es": ">=3.3.4"
solves this issue for me too. So 3.2.2 = ok and 3.3.4 = ok, but 3.3.2 = NOT ok.Hey everyone, posting in case someone goes through the same headache as I did this morning.
Just finding this issue was extremely tough. The exception did not appear for me if I did a reload and had the dev server bundle my code. And if I uninstalled the app and ran
react-native run-android
, I also would not get this thrown exception (even if not connected to the dev server). The exception only appeared in production builds (no red screen to tell me why the app crashed) or after I created a new bundle and build without connecting to the dev server. Often it would look like the production build would crash and the dev build would be fine. I’m guessing this is affecting a lot of people who do not even realize it.@ohflying 's solution worked for me.
npm install -save uglify-es@3.2.2
Same Issue. Changing line 33 in
project/node_modules/react-native/Libraries/Components/Subscribable.js
to:worked for me! Thankyou!
I also have this issue. RN 0.51.0, running a release build on Android 7.