question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Error: undefined is not a constructor (evaluating 'new _globalThis.TextEncoder()')] when using suggested crypto-hash in react-native 0.63.x

See original GitHub issue

Intended outcome:

Follow the example and it works.

Actual outcome:

Follow the example and get this error:

[Error: undefined is not a constructor (evaluating 'new _globalThis.TextEncoder()')]

How to reproduce the issue:

Follow this example with an Apollo Client in React Native.

So far, everything has worked in both web and mobile as far as our Apollo Client usage until this. Is there a recommended alternative or is this a bug?

Versions

  System:
    OS: macOS 10.15.7
  Binaries:
    Node: 14.15.0 - ~/.nvm/versions/node/v14.15.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.15.0/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.15.0/bin/npm
  Browsers:
    Chrome: 89.0.4389.128
    Safari: 14.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
benjamncommented, Apr 30, 2021

@eliw00d Apollo Client doesn’t use TextEncoder directly anywhere in our codebase, but perhaps you can track this down by defining a global getter function that shows the stack trace?

Object.defineProperty(globalThis, "TextEncoder", {
  get() {
    console.trace(); // Not sure if React Native supports console.trace, but you get the idea?
    console.error("See trace above to find out who tried to access globalThis.TextEncoder");
    debugger; // Another way to intercept references to TextEncoder.
    return null;
  },
})

I wouldn’t recommend leaving this getter in your application (this is just for debugging).

1reaction
eliw00dcommented, Apr 30, 2021

I was able to get it to work by using react-native-sha256.

I also tried this but was not able to get it to work (due to the reasons specified in my comment there).

Read more comments on GitHub >

github_iconTop Results From Across the Web

(React-Native) undefined is not a constructor evaluating ' ...
The error says that you are FormData is undefined. Since it is not part of react native, you probably have to download it...
Read more >
Passing props and undefined is not a constructor - Svelte
Just wiring up basic props and getting an error. ... TypeError: undefined is not a constructor (evaluating 'new Foo({ props: { number: 42...
Read more >
jest typeerror: class extends value
When attempting to mock Stack with jest, a TypeError "Class extends value undefined is not a constructor or null" is thrown. I need...
Read more >
react - ReactJS TypeError "not a constructor" on running a ...
ReactJS TypeError "not a constructor" on running a component with Carto ... This is the constructor of my React Component:
Read more >
Understanding React Component Constructor
render(<Hello />, document.getElementById('container'));. When you use the setState() method in React, it does more than just assign a new value ...
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