Error: jQuery requires a window with a document

后端 未结 12 2345
说谎
说谎 2020-11-29 00:43

So everything was working just fine and great until doing npm update and now things do not work quite as they used to.

A little background: in my code I use jquery

12条回答
  •  青春惊慌失措
    2020-11-29 01:15

    jsdom seems to have a new version therefore now it works on a slightly different way. Here you have an example:

    const { JSDOM } = require("jsdom");
    const myJSDom = new JSDOM (html);
    const $ = require('jquery')(myJSDom.window);
    

    Now you can search as you used to do on jQuery:

    $("

    ").html("The title");

    Mind the jQuery installation as you should write jquery all lowercase, like npm install jquery.

提交回复
热议问题