When importing JSDOM to my page, I get the following error during preview:
Cannot find module 'assert' in 'asn1/lib/ber'
This happens when I add this line:
import JSDOM from 'jsdom';
I’ve tried different variants too:
// This doesn't work
import { JSDOM } from 'jsdom';
// This neither
const jsdom = require("jsdom");
Any ideas?
Thanks.
The JSDOM package should be imported into backend code. The backend functions are then invoked from the frontend (page) code.
Sadly, I’m still getting errors with JSDOM even when importing in a backend file, whether it’s a .jsw or .js file.
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
export function getJSDOMContainer(id) {
//const dom = new JSDOM("<div id='"+id+"'></div>").window;
console.log (id);
}
When testing the function:

Am I missing something?
Thanks.
Welp, I gave it a try myself using one of the examples from the JSDOM documentation.
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
export function getJSDOMContainer(str) {
console.log(str);
const dom = new JSDOM(`<!DOCTYPE html><p>${str}</p>`);
console.log(dom.window.document.querySelector("p").textContent);
let ret = dom.window.document.querySelector("p").textContent;
return ret;
}
Here’s my test and the output:
So, I got something working at least. I can’t really say what’s wrong with your test. Unfortunately, we (Wix) are unable to provide support for NPM libraries, as they are really out of our control. You should check with the author’s page on Github, or perhaps someone here on the forum has some experience.
Huh, what an odd issue.
It still doesn’t work today (I was naively hoping it could be from Wix’s side and that it would magically resole overnight :p), even with your example. I tried with another browser, also tried to allow all cookies etc. To no avail.
I will try from a different computer (I really don’t think how this could be a client issue but a man’s desperate lol). Otherwise, I might also try with a VPN to change my location, who knows. Apart from that, I’m running out of ideas.
Anyhow thank you for trying. It’s good to know it’s at least supposed to work!
“naively hoping it could be from Wix’s side”… What’s naive about that? I’m always hoping it’s someone else’s problem.
Hopefully you’ll get this worked out. Maybe the package’s support on their Github page will be able to help.
And yeah, the “overnight” thing never works for me either.
So, I’ve tried with a Windows computer and my own Linux computer, also with a VPN. None of this worked.
This is the error that happens when I run the test:
I’m going to try on an actual test page with the rest of my content to see if it would work in a standard environment (that would mean the problem lies in with the testing mechanism, which I can live with).
After that, I’ll try opening an issue on the GitHub page.
I’ll let you know.
@yisrael-wix It’s rather that I’m always assuming that the problem is from my side first!
The correct sentence would rather be “I was naively hoping it would resolve overnight”… and indeed this rarely happens 
Hey did anyone solve this JSDom issue? I have tried import/require in my backend code, but it still produces an error for me.
I am facing same issue. @Anyone help me?
I install jsdom in npm packages and trying to use that.
I tried require and import statement, it is always giving same 500 error.
Having the same issue, jsdom not loading from npm packages