• Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

453
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?).

9 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.