You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fast-png dependency creates a latin1 TextDecoder at import-time, crashing runtimes that don't contain latin1 support #1162
OS: Android (also reproducible on iOS with Hermes)
Transport: rosbridge WebSocket
Description
After upgrading from roslib 1.4.1 to 2.x, the app crashes at startup in a React Native environment using Hermes. The error appears to originate from dependencies (likely BSON / Buffer usage) that rely on encodings unsupported by Hermes.
I think we certainly should support React, etc. since it's how most people write JS apps.
This seems like a bug internal to bson, unfortunately. Are you actually using BSON on your rosbridge, or is roslibjs erroneously attempting to do BSON things where it's not needed?
changed the title [-]React Native (Expo / Hermes) crashes with RangeError: Unknown encoding: latin1 when using roslib v2+[/-][+]`fast-png` dependency creates a `latin1` TextDecoder at import-time, crashing runtimes that don't contain `latin1` support[/+]on Mar 2, 2026
I just tested this PR in a React Native environment, and I’m happy to report that the TextDecoder('latin1') error (triggered by the fast-png dependency) is no longer occurring. Everything is working smoothly now!
For other developers using this in React Native, just a small tip: since roslib depends on uuid, you need to import react-native-get-random-values at the very top of your entry file to provide the necessary polyfill.
The important detail was initialization order: initialize Expo, install the polyfills, then load Expo Router.
// index.js — set package.json "main" to "index.js"import'expo';import'react-native-get-random-values';import'./utils/textDecoderPolyfill';import'expo-router/entry';
// utils/textDecoderPolyfill.jstry{newglobalThis.TextDecoder('latin1').decode();}catch{// Under Metro, text-encoding can preserve and re-export Expo's// existing UTF-8-only decoder. Clear it before loading the polyfill.globalThis.TextDecoder=undefined;globalThis.TextDecoder=require('text-encoding').TextDecoder;}
Simply assigning require('text-encoding').TextDecoder without first clearing the existing decoder still produced the same latin1 crash on Android, even though it passed our initial Node test.
react-native-get-random-values supplies the crypto API needed by UUID/BSON. Rebuild the Android app after installing it because it includes a native module.
We also needed a separate Metro resolver adjustment to select ws’s browser entry, since Metro otherwise tried to bundle the unused Node transport.
Activity
MatthijsBurgh commentedon Feb 25, 2026
I don't think we support any frameworks like react. They work or not. We are open to fixes that extend compatibility.
@EzraBrooks do you have any tips to get it working?
EzraBrooks commentedon Mar 2, 2026
I think we certainly should support React, etc. since it's how most people write JS apps.
This seems like a bug internal to
bson, unfortunately. Are you actually using BSON on your rosbridge, or is roslibjs erroneously attempting to do BSON things where it's not needed?EzraBrooks commentedon Mar 2, 2026
Actually, this line in
fast-pngappears to be the culprit:https://github.com/image-js/fast-png/blob/77a4479d68d84246793f58f7bbf2a2ea3a80c0f5/src/helpers/text.ts#L11
A globally-scoped
TextDecoderthat is constructed at import time.I think perhaps roslibjs can lazy-load PNG support.
[-]React Native (Expo / Hermes) crashes with RangeError: Unknown encoding: latin1 when using roslib v2+[/-][+]`fast-png` dependency creates a `latin1` TextDecoder at import-time, crashing runtimes that don't contain `latin1` support[/+]cn1001wang commentedon Mar 11, 2026
Hi @EzraBrooks,
I just tested this PR in a React Native environment, and I’m happy to report that the TextDecoder('latin1') error (triggered by the fast-png dependency) is no longer occurring. Everything is working smoothly now!
For other developers using this in React Native, just a small tip: since roslib depends on uuid, you need to import react-native-get-random-values at the very top of your entry file to provide the necessary polyfill.
ahmedbilal205 commentedon Oct 26, 2026
I got
roslib@2.1.0working on a physical Android tablet using Expo SDK 57, React Native 0.86, and Hermes with two polyfills:The important detail was initialization order: initialize Expo, install the polyfills, then load Expo Router.
Simply assigning
require('text-encoding').TextDecoderwithout first clearing the existing decoder still produced the samelatin1crash on Android, even though it passed our initial Node test.react-native-get-random-valuessupplies the crypto API needed by UUID/BSON. Rebuild the Android app after installing it because it includes a native module.We also needed a separate Metro resolver adjustment to select
ws’s browser entry, since Metro otherwise tried to bundle the unused Node transport.