React Native - warn message sends Can't find variable: TextEncoder

See original GitHub issue

I am using Stompjs to connect with Apache ActiveMQ and Spring Server but when I run application I receive a console warning message and after I navigate to another Screen with lots of data I receive this error non-stop as if it went to a loop.

Error:

 [Unhandled promise rejection: ReferenceError: Can't find variable: TextEncoder]
- node_modules/@stomp/stompjs/bundles/stomp.umd.js:1538:30 in Parser
- node_modules/@stomp/stompjs/bundles/stomp.umd.js:1832:16 in start
- ... 13 more stack frames from framework internals

I believe this has to do with the package rather than my code

const stompConfig = {
    reconnectDelay: 100,
    heartbeatIncoming: 0,
    heartbeatOutgoing: 0,
    debug: function(str) {
      console.log(str);
    }
  }

  stompConfig.webSocketFactory = () => {
    return new SockJS(
        "http://192.168.1.2:8080/"
    );
  };
  client = new Client(stompConfig);

  client.onConnect = function(frame) {
    console.log('frame', frame.body);
  };

  client.onStompError = function(frame) {
    console.log('Broker reported error: ', frame.headers['message']);
    console.log('Additional details: ', frame.body);
  };

  client.activate();

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ufukomercommented, Dec 15, 2021

@kum-deepak thanks for the link @madsams thanks for telling where to focus 😃

React Native already supports WebSocket thus we only need to add text-encoder to global TextEncoder, TextDecoder objects:

const TextEncodingPolyfill = require('text-encoding');

Object.assign(global, {
  TextEncoder: TextEncodingPolyfill.TextEncoder,
  TextDecoder: TextEncodingPolyfill.TextDecoder,
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: Can't find variable: TextEncoder
I got the same error using stomp.js socket. All I did was put. import * as encoding from 'text-encoding';. in App.js and works...
Read more >
Web terminals don't work in Safari: `ReferenceError: can't find ...
Web terminals don't work in Safari: `ReferenceError: can't find variable: TextDecoder`. Summary. Web terminals raise a JavaScript error if ...
Read more >
Configuring Jest
All modules used in your tests will have a replacement implementation, keeping the API surface. Example: utils.js. export default {
Read more >
Node.js v19.3.0 Documentation
Environment variable options; Persistent history; Using the Node.js REPL with advanced line-editors; Starting multiple REPL instances against a single ...
Read more >
Edge Runtime
The Next.js Edge Runtime is based on standard Web APIs. ... your code could contain (or import) some dynamic code evaluation statements which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found