Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using TextEncoder with hermes #948

Closed
ahmed-adly-khalil opened this issue Mar 26, 2023 · 13 comments
Closed

using TextEncoder with hermes #948

ahmed-adly-khalil opened this issue Mar 26, 2023 · 13 comments
Labels
enhancement New feature or request

Comments

@ahmed-adly-khalil
Copy link

ahmed-adly-khalil commented Mar 26, 2023

Problem

i'm trying to use https://github.com/nats-io/nats.ws in react native app, and getting the error ReferenceError: Property 'TextEncoder' doesn't exist, js engine: hermes

The package https://github.com/nats-io/nats.ws uses web sockets to connect to NATS server and used TextEncoder to serialize messages before sending to NATS

Solution

I understand that hermes leaves out some features from other JS engines like v8 in favor of performance, is there a way to add specific features like TextEncoder on the app level?

More Context

https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder has the spec for TextEncoder

@ahmed-adly-khalil ahmed-adly-khalil added the enhancement New feature or request label Mar 26, 2023
@ahmed-adly-khalil
Copy link
Author

this worked for me
npm install --save text-encoding
create globals.js on the app root and add global.TextEncoder = require('text-encoding').TextEncoder;
import it inside index.js import './globals.js';

@tmikov
Copy link
Contributor

tmikov commented Mar 27, 2023

I also want to note that TextEncoder is not a part of the ECMAScript spec. As far as I can tell, it is defined by WHATWG as part of the web APIs.

The distinction is subtle but important. JS engines implement ECMAScript, but web browsers implement the web standards. Hermes is only a JS engine, not a web browser.

With that said, undeniably there are useful APIs defined as part of the web standards. Theoretically it would be nice if there was a second repository with "add-ons" like this one.

@tmikov
Copy link
Contributor

tmikov commented Jul 28, 2023

FYI. #1072 .

@tmikov
Copy link
Contributor

tmikov commented Feb 17, 2024

@ahmed-adly-khalil as of 3863a36, Hermes now supports TextEncoder.

efstathiosntonas referenced this issue in facebook/react-native Feb 28, 2024
@anfearco
Copy link

@ahmed-adly-khalil as of 3863a36, Hermes now supports TextEncoder.

Is it already available with RN 0.73.6?

@tmikov
Copy link
Contributor

tmikov commented Mar 21, 2024

@anfearco new features are not automatically picked in RN point releases. I think RN's policy is that point releases only contain bug fixes, but I am not sure. It is possible that if people requested it, they might consider including it in the next point release.

@ranile
Copy link

ranile commented Mar 29, 2024

@ahmed-adly-khalil as of 3863a36, Hermes now supports TextEncoder.

Is it already available with RN 0.73.6?

The commit is tagged hermes-2024-02-20-RNv0.74.0-999cfd9979b5f57b1269119679ab8cdf60897de9 so I would assume not

@anfearco
Copy link

anfearco commented Apr 5, 2024

@anfearco new features are not automatically picked in RN point releases. I think RN's policy is that point releases only contain bug fixes, but I am not sure. It is possible that if people requested it, they might consider including it in the next point release.

@tmikov That makes sense. Thanks for the response!

@abhinav-0107
Copy link

@ahmed-adly-khalil Worked for me. Thanks!

@iamkem
Copy link

iamkem commented Jun 3, 2024

this worked for me npm install --save text-encoding create globals.js on the app root and add global.TextEncoder = require('text-encoding').TextEncoder; import it inside index.js import './globals.js';

Thanks, it's save my day

@g-otn
Copy link

g-otn commented Jul 15, 2024

If you need to polyfill, text-encoding is deprecated, use fast-text-encoder instead.

@webjay
Copy link

webjay commented Sep 14, 2024

import "text-encoding-polyfill" fixed it here

@Sorono-Dev
Copy link

This was the best solution for me : https://github.com/EvanBacon/text-decoder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants