cosmjs: Cosmjs incompatibility with ES2018

Hi everyone, I’m trying to create a new rn project including cosmjs. After the inclusion, if I try to use part of the packages included on cosmjs all works like a charm. However, if I try to import the tendermint-rpc package or the stargate one, the inclusion fails. Giving a few debugging, I saw that the issue is linked to BigInt, which is on this repo, included as a native call (since it is available from ES10).

ReferenceError: Can't find variable: BigInt

Maybe I’m missing something. Is there anyone who could help in including and using cosmjs (fully) inside a React Native project?


Useful information

React native version: 0.68.2 Tested with both cosmjs version: 0.24.0-alpha.25 and latest

Thank you.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 26 (11 by maintainers)

Most upvoted comments

@Giorgionocera Hey man, could you provide a demo that rn uses part of the packages included on cosmjs and it works well. THX! I cannot run rn with cosmjs.

Hi there, after the release of RN 0.70.0, they added support to BigInt in Hermes. Now it is also possible to use the latest releases of CosmJS, to facilitate the creation of an RN project with CosmJS, I have created a template for the react-native CLI.

It is obviously an open source template! You all can use it, and, most importantly, can contribute in improving it!

@Giorgionocera Hello, how to introduce all this package?

But looking back to cosmjs main page it says “Our current Javascript target standard is ES2018” so we should fix it in the main version. Upgrading the target standard from 2018 to 2020 seems a big jump all together. Either recompile from @noble/hashes up using the babel transform or reverting to the previously used (or a new one) hashing library. This is indeed not even an issue related with React Native itself is just that the supported ES standard is different from the supposed officially supported standard. Capture

Maybe you can create a Webpack debug bundle, this contains all dependency code in one file. Thenuse text search for bigint/BigInt.

I think that we are going to get them eventually so going forward I don’t see any problem with starting to use BigInt but as we don’t know when we should fix that in this version first. I will investigate the problem further and get back to you

Could you provide all error output you can get using the latest CosmJS release? As far as I can tell, we don’t use BigInt/bigint directly. It might be a dependency though.

From CosmJS 0.30.0 onwards we target es2020 and make use of BigInt in more and more places. Happy to hear that there are solutins emerging for the React Native ecosystem.

Hello, we created a fork of cosmjs called cosmjs-rn that you can find here working with version 0.27.1. Moreover, we published its build on npm and you can install it by looking for @cosmjs.rn.

To use it, you have to install and run rn-nodeify (https://www.npmjs.com/package/rn-nodeify). If you are using expo this requires ejecting the android/ios project and in the android project case even running jetifier. Using expo for this kind of project is not recommended.

To recap:

  1. Install packages from @cosmjs-rn and not @cosmjs
  2. Install rn-nodeify as dev dependency (yarn add -D rn-nodeify or npm i -D rn-nodeify). If you are using expo use yarn (here, if you are using expo, eject native projects and install jetifier)
  3. npx rn-nodeify --install --hack
  4. In App.tsx (or index.tsx) add import "./shim.js"
  5. Uncomment require('crypto') from shim.js
  6. jetify
  7. yarn android / yarn ios

Every time you install a package you have to delete yarn.lock and do

  1. npx rn-nodeify --install --hack
  2. jetify
  3. yarn android or yarn ios

@Giorgionocera I’ll try, thanks for the reply

At least for me that’s the full console log from application start. I have to mention that it happens on the stargate branch of the library. proto-sign for examples works (with rn-nodeify) just fine.

I have the same issue. The full error is:

ReferenceError: Can't find variable: BigInt
Android Running app on Android SDK built for x86
Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called. 

And I think it could be (but I’m not sure) a dependency because the only place I could find BigInt is the .pnp.cjs file at root generated by yarn. Maybe the package using it has a fallback compatibility mode and the library just needs to be compiled for both environment (the one supporting BigInt and the one that does not).