Expo React Native Can't find variable: TextDecoder

Viewed 261

So for some reason i'm having this bug when i try to run the app on the Expo Go app in my phone. Apparently is ok if i run on the web browser.

This is the error log

ReferenceError: Can't find variable: TextDecoder

Stack trace:
node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
node_modules\react-native\Libraries\Core\ExceptionsManager.js:95:4 in reportException
node_modules\react-native\Libraries\Core\ExceptionsManager.js:141:19 in handleException
node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in handleError
node_modules@react-native\polyfills\error-guard.js:49:36 in ErrorUtils.reportFatalError
node_modules\metro-runtime\src\polyfills\require.js:203:6 in guardedLoadModule
http://192.168.0.29:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:190345:3 in global code ...

2 Answers

This happened to us too, on an app that had used to work in an older Expo version. The solution for us was to add this line to our .babelrc.js file:

"presets": [
  ["babel-preset-expo", {
    lazyImports: true, // <<< The fix
  ]
]

Got over the problem by doing this;

npm install text-encoding

npm install big-integer

and pasting this code inside node_modules>react-native>Libraries>LogBox

const TextEncodingPolyfill = require('text-encoding');
const BigInt = require('big-integer')
Object.assign(global, {
  TextEncoder: TextEncodingPolyfill.TextEncoder,
  TextDecoder: TextEncodingPolyfill.TextDecoder,
  BigInt: BigInt,
});
Related