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.

TextEncoder issues on 26.0.1

See original GitHub issue

🐛 Bug Report

The TextEncoder.encode does not seem to yield a valid U8a, or rather, it cannot be compared. When the output from this is passed into a function expecting a Uint8Array it does indeed fail.

To Reproduce

This is a failing test -

it('encodes string as Uint8array', (): void => {
    expect(
      new TextEncoder().encode('Привет, мир!')
    ).toEqual(
      new Uint8Array([208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130, 44, 32, 208, 188, 208, 184, 209, 128, 33])
    );
  });

The output does not match, rather it fails with -

    expect(received).toEqual(expected) // deep equality

    - Expected  - 23
    + Received  + 23

    - Uint8Array [
    -   208,
    -   159,
    -   209,
    -   128,
    -   208,
    -   184,
    -   208,
    -   178,
    -   208,
    -   181,
    -   209,
    -   130,
    -   44,
    -   32,
    -   208,
    -   188,
    -   208,
    -   184,
    -   209,
    -   128,
    -   33,
    - ]
    + Uint8Array {
    +   "0": 208,
    +   "1": 159,
    +   "10": 209,
    +   "11": 130,
    +   "12": 44,
    +   "13": 32,
    +   "14": 208,
    +   "15": 188,
    +   "16": 208,
    +   "17": 184,
    +   "18": 209,
    +   "19": 128,
    +   "2": 209,
    +   "20": 33,
    +   "3": 128,
    +   "4": 208,
    +   "5": 184,
    +   "6": 208,
    +   "7": 178,
    +   "8": 208,
    +   "9": 181,
    + }

Expected behavior

It was still working on the 25.4.x version before I updated.

Link to repl or repo (highly encouraged)

Failing test included above.

envinfo

  System:
    OS: macOS 10.15.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 13.8.0 - /usr/local/bin/node
    Yarn: 2.0.0-rc.30 - /usr/local/bin/yarn
    npm: 6.13.7 - /usr/local/bin/npm

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
andrevenanciocommented, Aug 24, 2021

Is there any progress on this issue?

10reactions
jacogrcommented, May 11, 2020

I dug, in the case of no TextEncoder it injects a polyfill in the project where this was uncovered, which is this -

if (typeof TextEncoder === 'undefined') {
 global.TextEncoder = require('util').TextEncoder;
}

So the issue is exactly the same as @TrySound reported - since doing the above will no doubt use Buffer internally, so the test-case he has is the simplest and the actual underlying cause -

  it('has Buffer & Uint8array equivalency', () => {
    expect(Buffer.from('') instanceof Uint8Array).toBeTruthy();
  });

Sorry about the confusion, it has been literally 2 years since that polyfill was added. (Since it just worked in the meantime, totally lost track of it)

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: TextEncoder is not defined - Stack Overflow
This issue occurs in node 10 or lower version only. To resolve this issue upgrade node version to 12 or higher and then...
Read more >
jest-environment-jsdom | Yarn - Package Manager
26.0.1. Fixes. [jest-circus] Backward compatibility for deprecated ... [jest-environment-node] Fix TextEncoder.encode not referencing same global Uint8Array ...
Read more >
TextEncoder - Web APIs - MDN Web Docs
Chrome Edge TextEncoder Full support. Chrome38. Toggle history Full support. Edge79. To... TextEncoder() constructor Full support. Chrome38. Toggle history Full support. Edge79. To... encode Full support....
Read more >
ipfs-http-client/CHANGELOG.md - UNPKG
227, * dont include util.textencoder in the browser ... 1190, ## [26.0.1](https://github.com/ipfs/js-ipfs-http-client/compare/v26.0.0...v26.0.1) (2018-10-30).
Read more >
matteoluigi's Content - Page 5 - Vectorworks Community Board
yeah, the only problems are when rendering the OpenGL viewports. Of course, my college mentioned, that he didn't have problems from the beginning......
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