Skip to content

Instantly share code, notes, and snippets.

@zivc
Created September 26, 2022 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zivc/70a0965d673c41df27461bffda12b9f2 to your computer and use it in GitHub Desktop.
Save zivc/70a0965d673c41df27461bffda12b9f2 to your computer and use it in GitHub Desktop.
ReferenceError: Can't find variable: TextDecoder

Error:

Using expo react-native and realm-web for iOS etc

ReferenceError: Can't find variable: TextDecoder

Solution:

Install dependencies

expo install text-encoding big-integer

Create polyfill file at polyfills/TextEncoding.js

import TextEncodingPolyfill from 'text-encoding';
import BigInt from 'big-integer';
Object.assign(global, {
    TextEncoder: TextEncodingPolyfill.TextEncoder,
    TextDecoder: TextEncodingPolyfill.TextDecoder,
    BigInt: BigInt,
});

Update index.js (if you have one) or App.js with the following at the top

import "./polyfills/TextEncoding";

Note: Using Babel for polyfills means you have to eject. So do this instead.

Restart expo using expo start -c -i

iOS should now boot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment