Closed ahmed-adly-khalil closed 1 year ago
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';
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.
@ahmed-adly-khalil as of https://github.com/facebook/hermes/commit/3863a36a53005dd1e6d39ea0d4ef5573bafde910, Hermes now supports TextEncoder.
@ahmed-adly-khalil as of 3863a36, Hermes now supports TextEncoder.
Is it already available with RN 0.73.6?
@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.
@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 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!
@ahmed-adly-khalil Worked for me. Thanks!
this worked for me
npm install --save text-encoding
create globals.js on the app root and addglobal.TextEncoder = require('text-encoding').TextEncoder;
import it inside index.jsimport './globals.js';
Thanks, it's save my day
If you need to polyfill, text-encoding
is deprecated, use fast-text-encoder instead.
import "text-encoding-polyfill"
fixed it here
This was the best solution for me : https://github.com/EvanBacon/text-decoder
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 NATSSolution
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