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

ReferenceError: Can't find variable: BigInt #6495

Closed
zahir-dct opened this issue Oct 11, 2023 · 8 comments
Closed

ReferenceError: Can't find variable: BigInt #6495

zahir-dct opened this issue Oct 11, 2023 · 8 comments
Labels

Comments

@zahir-dct
Copy link

Actual behavior

App crashes

Steps to reproduce the behavior

add web3 package to an expo app

Logs

ERROR ReferenceError: Can't find variable: BigInt

ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

Environment

"expo": "~47.0.12",
"react": "18.1.0",
"react-native": "0.70.8",
"web3": "^1.8.2",

Note

I removed "^" from "^1.8.2", the app doesn't crash

@jdevcs jdevcs added the 4.x 4.0 related label Oct 16, 2023
@jdevcs
Copy link
Contributor

jdevcs commented Oct 16, 2023

@zahir-dct can you create a small repository on GitHub or create a sample on a Cloud IDE like https://codesandbox.io/ with above error.

@zahir-dct
Copy link
Author

@zahir-dct can you create a small repository on GitHub or create a sample on a Cloud IDE like https://codesandbox.io/ with above error.

https://github.com/zahir-dct/reproduction

@Muhammad-Altabba
Copy link
Contributor

Hi @zahir-dct,
Did you try with web3.js version 4.x?
And does adding /* global BigInt */ to the top of your app.js would resolve the problem?
Thanks,

@jdevcs jdevcs removed the 4.x 4.0 related label Oct 17, 2023
@zahir-dct
Copy link
Author

Hi @zahir-dct, Did you try with web3.js version 4.x? And does adding /* global BigInt */ to the top of your app.js would resolve the problem? Thanks,

I already tried version 4.x, but it doesn't work.
Adding big-integer would be a workaround. It doesn't fix the actual issue.

@Muhammad-Altabba
Copy link
Contributor

Muhammad-Altabba commented Oct 18, 2023

Hi @zahir-dct
I checked the issue, and I confirm that it is with expo. So, you need to open an issue at their side. They do not support BigInt.

By the way, I tried adding /* global BigInt */. And I also tried doing a ployfill using the big-integer package. And both did not work with expo. So, you may try to "eject" from expo but there could be some other solutions. And to find the right way you would need to check with them.

However, I will keep this issue open in order to check for possible workarounds till expo supports BigInt.

@Muhammad-Altabba
Copy link
Contributor

Muhammad-Altabba commented Oct 19, 2023

I am closing this issue as there is nothing to be done at web3.js.

However, for those facing this error, here is a way to work around it (as mentioned in facebook/react-native#28492 (comment)):

  1. Add rn-nodeify to your dev dependencies with: yarn add --dev rn-nodeify.
  2. Add big-integer package with: yarn add big-integer.
  3. Create a file named shim.js at the root of your project. And add the following pollyfill to it:
if (typeof BigInt === 'undefined') {
    global.BigInt = require('big-integer');
}
  1. Import your shim.js file at the top of your App.js:
// make sure you use `import` and not `require`!
import './shim.js'

However, if the above did not work, or if you did not like the way it works, I suggest to check with, rn-nodeify, expo and react-native...

@zahir-dct
Copy link
Author

Actual behavior

App crashes

Steps to reproduce the behavior

add web3 package to an expo app

Logs

ERROR ReferenceError: Can't find variable: BigInt

ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter. A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter. A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

Environment

"expo": "~47.0.12", "react": "18.1.0", "react-native": "0.70.8", "web3": "^1.8.2",

Note

I removed "^" from "^1.8.2", the app doesn't crash

react-native 0.70 (expo sdk 47) does not support BigInt. please try to update to latest sdk for the BigInt support.
expo/expo#24960 (comment)

@noname0486
Copy link

I am closing this issue as there is nothing to be done at web3.js.

However, for those facing this error, here is a way to work around it (as mentioned in facebook/react-native#28492 (comment)):

  1. Add rn-nodeify to your dev dependencies with: yarn add --dev rn-nodeify.
  2. Add big-integer package with: yarn add big-integer.
  3. Create a file named shim.js at the root of your project. And add the following pollyfill to it:
if (typeof BigInt === 'undefined') {
    global.BigInt = require('big-integer');
}
  1. Import your shim.js file at the top of your App.js:
// make sure you use `import` and not `require`!
import './shim.js'

However, if the above did not work, or if you did not like the way it works, I suggest to check with, rn-nodeify, expo and react-native...

It work with my project. Thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants