Skip to content

Bug: TextDecoder doesn’t exist in React Native environment #13

Description

@Junior580

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)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions