Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

736
Views
ReferenceError: TextEncoder is not defined when importing jsdom library

I have these two files:

test.js:

const jsdom = require("jsdom");

const hello  = () =>  {
  console.log("hello!");
};


module.exports = {
    hello
};

and

server.js:

const hello = require('./stuff/test');

hello.hello();

directory structure:

myprojectfolder
             backend
                    src
                       stuff
                           test.js
                       server.js

When I run server.js I get the ReferenceError: TextEncoder is not defined error:

/home/myusername/projects/myprojectfolder/node_modules/whatwg-url/lib/encoding.js:2
const utf8Encoder = new TextEncoder();
                    ^

ReferenceError: TextEncoder is not defined

If I remove const jsdom = require("jsdom"); line from test.js, server.js runs fine and without any errors (outputs hello).

Why does it happen and how do I fix it (while still being able to import and use jsdom inside test.js?).

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!