Jsdom NPM package broken

according to the documentation GitHub - jsdom/jsdom: A JavaScript implementation of various web standards, for use with Node.js

to setup jsdom you have the following

import { require } from ‘jsdom’
const jsdom = require(“jsdom”);

when trying this i get

Uncaught (in promise) TypeError: (0 , _jsdom.require) is not a function

To use nodeJS within Wix, see the tutorial here.
https://support.wix.com/en/article/corvid-managing-external-code-libraries-with-the-package-manager

Hi

I followed that article and have done as it explains. There is something wrong with the package being used. The web has many support references to a bug in some of the releases that do this. Can you test it to see if you can repllicate. Just install jsdom and try instantiate a basic object from it.

import {jsdom} from ‘jsdom’

var dom = jsdom. require (“jsdom”);

Uncaught (in promise) TypeError: Cannot read property ‘require’ of undefined
at test (backend/scraper.jsw:27:19)

might be related - from the documentation

The latest versions of jsdom require Node.js v8 or newer. (Versions of jsdom below v12 still work with Node.js v6, but are unsupported.)

Wix has 12.2

Note that as of our 4.0.0 release, jsdom no longer works with Node.js™, and instead requires io.js. You are still welcome to install a release in the 3.x series if you are stuck on legacy technology like Node.js™.

Although, it has merged with the Node.js project again. There won’t be any further io.js releases. All of the features in io.js are available in Node.js v4 and above.

As it is really a bug within JSDOM, you are best suited going to their own pages.
https://groups.google.com/forum/#!forum/jsdom
https://github.com/jsdom/jsdom/issues

I need to be able to parse html from a fetch - can you suggest anything

Uncaught (in promise) TypeError: Cannot read property ‘require’ of undefined
at test (backend/scraper.jsw:27:19)

Cannot read property ‘title’ of undefined, this means that you are trying to access the title property of something that is undefined, so, at the time you are trying to access these values they are not yet defined.

What are you requiring about as it can’t read the properties of it if it is undefined through your code.
What promise are you trying to return?
Maybe the call method needs to be asynchronous and you are trying to access the result of it as if it was synchronous.

the library doesnt work as you have stated. I am a bit stuck now as to how to parse hmtl from a website without being able to install a helper library it wil end up as ugly javascript code. not really elegant and a feature wix should support with at least one library.

same issue with cheerio

can you guys please remove npm packages that don’t work or upgrade them (prefferably)

You can always look at trying Wix Fetch or HTTP Functions.
https://support.wix.com/en/article/corvid-accessing-third-party-services-with-the-fetch-api
https://support.wix.com/en/article/corvid-calling-server-side-code-from-the-front-end-with-web-modules
https://www.wix.com/corvid/reference/wix-fetch.html
https://support.wix.com/en/article/corvid-exposing-a-site-api-with-http-functions
https://www.wix.com/corvid/reference/wix-http-functions.html

none of these are helpful unfortunately. I just want to access another site and get some info from that site. To do that i use wix fetch and then was hoping wix would have had a libary available in the npm packages to help me parse the html. Since i can’t use Jquery and both cheerio and jsdom don’t work, i now have to fork out money on another solution. This should be simple stuff yet wix has made it extremely frustrating and an entire day wasted trying to get a package to work on your site that isnt compatible with the current release. Shouldn’t wix at least have a disclaimer on the packages it makes available that they do not work with the current version. It also raises the question if i were to use a package (which i am), will it just stop working one day because wix have updated their platform and i find out through my user base that the site has areas that no longer work. Not exactly raising confidence experience and starting to wonder if wix was the right choice being so limited with its integration of libraries and bad at its communication of incompatibility.

Really frustrated by all of this. could have made progress today instead of wasting all this time on somehting that doesn’t work

Wix does not state that the libraries work. We make them available due to the demand from developers.

For support questions regarding a particular library, you will need to check with the developer.

The jsdom (and other variants) is required in order to parse HTML in backend code. That’s not just an issue with Wix. Nearly all XML/HTML parsers rely on the browser’s DOM. Backend code does not have a DOM, so it needs to supply a pretend one.

In the Manipulate SVG example, I use the xml-js NPM library available in the Wix Package Manager to modify an existing SVG image (which is an XML file). This library can also handle [some] HTML. You might be able to use that library for your purposes.
View the “Live” site in a browser page
Open the site template in the Wix Editor

How do you know that the package that is available does not work with the current version? Please supply more information so we can check on this.

Packages are screened and tested before adding to the Package Manager.

The ultimate source of information regarding the library is from the developer - that is, the NPM and Github pages.

@yisrael-wix

  1. its is dead simple to install either cheerio or jsdom from package manager
  2. without even running any logic, just calling require, the nodejs function to instantiate an object of the nodejs package, the following error is presented

Uncaught (in promise) TypeError: (0 , _jsdom.require) is not a function

thats no other code in the backend module but this

import { require } from ‘jsdom’
const jsdom = require(“jsdom”);

Same error surfaces for cheerio. Thats how i know it is the backend issue at wix and most likely a version issue, a bug, or compatibility issue. I encourage you to test it out yourself. The documentation for the library is here GitHub - jsdom/jsdom: A JavaScript implementation of various web standards, for use with Node.js

So how exactly was it tested on your end if i can’t even instantiate it? I am happy to eat humble pie if i am wrong and shout my appology and retraction of my statement. I should point out i am using another NPM package without issue but it doesnt need the require function.

it might have something to do with wix libraries and npm libraries with the word require. unless i am missing an import statement to access the require function but i see no documentation about this on the wix site. The giveaway is that the function require is blue in your dev studio meaning it is a special word like import so there might be an issue there. I have seen some issues on this forum before around it. maybe it is just a ui bug. quickly testing something

From the Github documentation for jsdom :

const jsdom = require("jsdom");
const { JSDOM } = jsdom;

The require statement gets flagged as en error, but it still works. You can use an import statement instead:

import jsdom from 'jsdom';

so it might be a UI bug that underlines require in your dev env? i thought that bug was fixed?

Just posted above a few seconds after you posted your message…

As I mention in my other post, require is a special word. Very special since it works even though it is flagged as an error. You can use import instead.

Choose whichever you prefer. I personally don’t like errors, but in spite of that fact, I often use require if the library’s docs use it. I like to be consistent with the docs.

I bug them about it, but I guess it’s just one of those things that they’ll “get to someday”.

Use import if the error bothers you.