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