Skip to content
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

iOS - Can't find variable: globalThis #4350

Closed
cristianoccazinsp opened this issue Feb 16, 2022 · 23 comments · Fixed by #4388, #4476 or #4653
Closed

iOS - Can't find variable: globalThis #4350

cristianoccazinsp opened this issue Feb 16, 2022 · 23 comments · Fixed by #4388, #4476 or #4653
Assignees
Labels
hermes Bugs and features related to running on the React Native hermes engine O-Community

Comments

@cristianoccazinsp
Copy link

cristianoccazinsp commented Feb 16, 2022

Description

Using 10.20.0-alpha.2 (but without actually using Hermes on iOS), reported the above crash for a user right on app startup.

Stacktrace & log output

ReferenceError
Can't find variable: globalThis

    node_modules/realm-network-transport/dist/bundle.react-native.es.js:91:43 
    node_modules/metro-runtime/src/polyfills/require.js:340:6 loadModuleImplementation
    node_modules/realm/lib/extensions.js:60:45 exports
    node_modules/realm/lib/react-native.js:45:24 
    node_modules/metro-runtime/src/polyfills/require.js:340:6 loadModuleImplementation
    src/db/index.js:8 
    node_modules/metro-runtime/src/polyfills/require.js:340:6 loadModuleImplementation
    src/App.js:31 
    node_modules/metro-runtime/src/polyfills/require.js:340:6 loadModuleImplementation
    node_modules/metro-runtime/src/polyfills/require.js:200:45 guardedLoadModule
    index.js:86:29 
    node_modules/regenerator-runtime/runtime.js:63:44 tryCatch
    node_modules/regenerator-runtime/runtime.js:294:30 
    node_modules/regenerator-runtime/runtime.js:63:44 tryCatch
    node_modules/regenerator-runtime/runtime.js:155:28 invoke
    node_modules/regenerator-runtime/runtime.js:165:19 
    node_modules/promise/setimmediate/core.js:37:14 tryCallOne
    node_modules/promise/setimmediate/core.js:123:25 
    node_modules/react-native/Libraries/Core/Timers/JSTimers.js:248:17 
    node_modules/react-native/Libraries/Core/Timers/JSTimers.js:112:6 _callTimer
    node_modules/react-native/Libraries/Core/Timers/JSTimers.js:166:15 _callReactNativeMicrotasksPass
    node_modules/react-native/Libraries/Core/Timers/JSTimers.js:418:11 callReactNativeMicrotasks
    node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:393:11 value
    node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:135:11 
    node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:370:8 value
    node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:134:17 value
    [native code] value
    [native code] value

### Can you reproduce a bug?
Not yet

### Reproduction Steps
Regular offline (non sync) usage.

### Version
10.20.0-alpha.2

### What SDK flavour are you using?
Local Database only

### Are you using encryption?
_No response_

### Platform OS and version(s)
iOS 12.1.1 (iPad Mini 3)

@cristianoccazinsp cristianoccazinsp added the hermes Bugs and features related to running on the React Native hermes engine label Feb 16, 2022
@kraenhansen
Copy link
Member

Impressive 🙂 I think this is only possible if we load before the runtime globals gets set?

@cristianoccazinsp
Copy link
Author

I'm amazed as well. I've only seen one user with this issue with an old device, so perhaps a slow start and a race condition?

The user still managed to trigger the issue 4 times, and then probably gave up.

Screen Shot 2022-02-16 at 12 10 36

The issue also happens right when importing realm:
import Realm from 'realm';

Could it be related to inlineRequires: true ?

@fronck
Copy link

fronck commented Feb 17, 2022

@cristianoccazinsp Thanks for reporting -- we'll look into it. Please let us know if you dig out more information.

@laxminarayan192
Copy link

laxminarayan192 commented Mar 1, 2022

"jsc-android": "^250230.2.1" solved issue for me, as i was having issue in android

@takameyer
Copy link
Contributor

takameyer commented Mar 2, 2022

@laxminarayan192 What version of jsc-android were you using before? I am a bit confused that updating JSC on android would fix your issue on iOS.

@takameyer
Copy link
Contributor

It appears globalThis support was added in iOS version 12.2 (WebKit/WebKit@2b424f0). So that would explain why users running on old devices would run into this issue.

@cristianoccazinsp
Copy link
Author

I'm getting the issue only on iOS. But you are right, these are all old devices.

Screen Shot 2022-03-02 at 09 33 28

@laxminarayan192
Copy link

@laxminarayan192 What version of jsc-android were you using before? I am a bit confused that updating JSC on android would fix your issue on iOS.

I was using jsc-android: "241213.1.0",

@takameyer takameyer mentioned this issue Mar 2, 2022
9 tasks
@takameyer
Copy link
Contributor

@cristianoccazinsp I created a PR that might solve the issue. Unfortunately, I do not have a good way to test this.

@takameyer
Copy link
Contributor

Although, the ipad mini mentioned above does have the ability to upgrade to 12.5, which would also fix the issue

@cristianoccazinsp
Copy link
Author

It's not easy to tell users to upgrade their ancient devices :D

@takameyer
Copy link
Contributor

@cristianoccazinsp That is true 😆 A fix is on the way.

@sync-by-unito
Copy link

sync-by-unito bot commented Mar 16, 2022

➤ Franck Franck commented:

Fixed by #4388

@cristianoccazinsp
Copy link
Author

@takameyer @kraenhansen I seem to be seeing the same crash logs with Realm 10.20.0-beta.4. Wasn't this resolved? Maybe not released yet?

ReferenceError
Can't find variable: globalThis

    node_modules/realm/lib/react-native/index.js:42:25 
    node_modules/metro-runtime/src/polyfills/require.js:340:6 loadModuleImplementation
    src/db/index.js:8 
model
iPad Air 2 (iPad5,3)

modelNumber
J81AP

osName
iOS

osVersion
11.2.6
runtimeVersions
{
  "clangVersion": "13.1.6 (clang-1316.0.21.2)",
  "osBuild": "15D100",
  "reactNative": "0.67.4",
  "reactNativeJsEngine": "jsc"
}

@takameyer
Copy link
Contributor

takameyer commented Apr 26, 2022

@cristianoccazinsp I believe this was released with 10.20.0-beta.5 and 10.16.0

@cristianoccazinsp
Copy link
Author

@takameyer we have released a new version using 10.20.0-beta.5, yet the error still shows.

ReferenceError Can't find variable: globalThis 
    node_modules/realm/lib/react-native/index.js:45:32 
    node_modules/metro-runtime/src/polyfills/require.js:340:6 loadModuleImplementation
    node_modules/realm/lib/index.native.js:20 
    node_modules/metro-runtime/src/polyfills/require.js:340:6 loadModuleImplementation
    src/db/index.js:8 
    node_modules/metro-runtime/src/polyfills/require.js:340:6 loadModuleImplementation
    src/App.js:30 
    node_modules/metro-runtime/src/polyfills/require.js:340:6 loadModuleImplementation
    node_modules/metro-runtime/src/polyfills/require.js:200:45 guardedLoadModule
    index.js:128:29 

Device: iPhone SE, iOS 12.0

@tomduncalf
Copy link
Contributor

tomduncalf commented Jun 13, 2022

Hey @cristianoccazinsp, sorry to hear you are still having issues. I'm going to try Realm out on a device with iOS 11 to see if I can reproduce the issue and I'll let you know how it goes.

@tomduncalf tomduncalf reopened this Jun 13, 2022
@tomduncalf
Copy link
Contributor

I was able to reproduce this on iOS 11, so will investigate further tomorrow.

@cristianoccazinsp
Copy link
Author

Thanks for the quick review!

@cristianoccazinsp
Copy link
Author

Not sure if just a coincidence, but beta.5 seems to be having this issue more frequently than beta.4. After the release, the error is being reported much more frequently.

Screen Shot 2022-06-14 at 09 16 22

Screen Shot 2022-06-14 at 09 16 52

@tomduncalf
Copy link
Contributor

tomduncalf commented Jun 14, 2022

Hey @cristianoccazinsp, I think that's a coincidence, from what I can see this would just 100% not work on iOS 11 (which I tested on) and from the sounds of things 12. I've got a fix in review, so hopefully we can get that into the next Hermes branch release (which is currently blocked on some test issues but we are working to resolve those this week)

@fronck
Copy link

fronck commented Jun 30, 2022

@cristianoccazinsp We've closed this issue for now. If the fix merged in the hermes branch doesn't work for you, feel free to re-open.

@cristianoccazinsp
Copy link
Author

@fronck what beta version can this fix be found at?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hermes Bugs and features related to running on the React Native hermes engine O-Community
Projects
None yet
6 participants