Skip to content

[React Native + Hermes] "utf-16le" error in h3-js causes crash on RN 0.76 #203

Open
@daminiR

Description

@daminiR

When using h3-js in a React Native 0.76 project with Hermes enabled, I encounter an error related to "utf-16le" encoding:
RangeError: Unknown encoding: utf-16le (normalized: utf-16le), js engine: hermes

It appears that Hermes does not support 'utf-16le' by default, so even if h3-js never actually calls it at runtime, the presence of new TextDecoder("utf-16le") can cause a crash.


Environment Details

  • React Native: 0.76.x
  • Hermes: Enabled
  • h3-js: 4.1.0
  • Platform: iOS & Android (via Expo or bare RN)

Steps to Reproduce

  1. Create a new React Native (0.76) project with Hermes enabled.

  2. Install h3-js (yarn add h3-js).

  3. Import a function from h3-js, for example:

    import { latLngToCell } from "h3-js";

Cause

Hermes doesn’t recognize 'utf-16le'. Inside the distribution files (e.g. node_modules/h3-js/dist/h3-js.js), there’s a line:

var UTF16Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-16le") : undefined;

Even if it’s never used at runtime, Hermes fails just by parsing it.

Temporary Workaround / Proposed Fix

I used patch-package to replace 'utf-16le' with 'utf-8' (or remove it entirely) in the compiled bundle.

Example patch diff:

- var UTF16Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-16le") : undefined;
+ var UTF16Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8") : undefined;

Request / Possible Solution

It would be great if the official distribution of h3-js either:
1. Removed this unused 'utf-16le' reference, or
2. Allowed a build flag / environment condition for React Native users so it doesn’t break Hermes.

I’m happy to contribute a PR if that’s helpful.

Additional Context
• Many RN devs upgrading from 0.74 to 0.76 are hitting this issue because Hermes is recommended by default in newer RN versions.
• Similar utf-16le encoding issues have affected other libraries in the RN + Hermes ecosystem. Removing or replacing 'utf-16le' has fixed them.

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