-
Notifications
You must be signed in to change notification settings - Fork 3
Description
When using uint8array-tools in a React Native 0.79.0 project, the following error occurs at runtime:
Uncaught Error: Property 'TextDecoder' doesn't exist
browser.js:12:21
const DECODER = new TextDecoder();
^ Property 'TextDecoder' doesn't exist
Affected file:
node_modules/uint8array-tools/src/mjs/browser.js
Possible Cause
React Native does not provide TextEncoder or TextDecoder in the global environment.
As a result, libraries that depend on them (like this one) will throw errors when used outside of Node.js or browsers.
This can be mitigated by adding a small polyfill using the text-encoding
package.
Suggested Fix:
Add a conditional polyfill at the top of browser.js (or detect the React Native environment and import text-encoding only when needed).
import 'text-encoding'
Environment
React Native: 0.79.0
uint8array-tools: latest npm version
Platform: iOS (also occurs on Android)