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.

Bumping to 0.16.0 - ReferenceError: TextEncoder is not defined

See original GitHub issue

When installing - "isomorphic-dompurify": "^0.16.0" I get the following error within a jest test that previously passed.

Error: ReferenceError: TextEncoder is not defined

js file:

import DOMPurify from "isomorphic-dompurify";

return DOMPurify.sanitize(input.trim(), { ADD_ATTR: ["target"] });

Test:

import sanitize from "./sanitizeHtml";

describe("sanitize", () => {
    it("remove js from input", () => {
        expect(sanitize("<img onload='alert(1)' />")).toEqual("<img>");
    });
});

Any ideas what this may be? Thanks in advance

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

38reactions
tinykitecommented, Jan 14, 2022

For anyone hitting this same issue, I was able to fix this on a project (which had a failing test due to this error) by including the following in my jest.setup.js file:

import { TextDecoder, TextEncoder } from 'util'

global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder
0reactions
aakashbacancycommented, Dec 15, 2022

I installed and I’m facing a similar issue. Everything seems fine.

The test suite failed to run

    ReferenceError: TextEncoder is not defined

I tried to print the process version using console.log(process.version) and it’s 14.7.0, still giving an error.

What is the right solution?

Node version: 14.7.0

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 >
TextEncoder is not defined | NodeJs | MongoDB | Solved
TextEncoder is not definedReference ErrorPath for required filenode_modules/whatwg-url/encoding.jsThanks# TextEncoder #mongodb #nodejs.
Read more >
How to Fix : TextEncoder is not defined - MongoDB - YouTube
Node.js #Node.js Version #solved # ReferenceError #howtoBy watching this video you will get a solution of most common node.js code deployment ...
Read more >
liquid-fire - UNPKG
_require = undefined;\n }\n\n\n Module.prototype.makeRequire = function() {\n var name = this.name;\n\n return this._require || (this.
Read more >
All Problems Tagged With Whatever - Code Grepper
... main.js:1 uncaught referenceerror: timelinemax is not defined · npm warn no repository field · java.lang.nullpointerexception: attempt to invoke virtual ...
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