Nodejs jQuery jsdom required

$.getJSON('https://api.twitch.tv/kraken/channels/' + SLoppierKitty7, function(channel) { if (channel["stream"] == null) { var live ="no" } else { var live ="yes" } 

this is my code but when i run it i get the following error

E: \ Sloppers bot \ node_modules \ jQuery \ lib \ node -jquery.js: 5 window = require ('jsdom'). jsdom (). createWindow (); ^

TypeError: require (...). jsdom (...). createWindow is not a function when creating (E: \ Sloppers bot \ node_modules \ jQuery \ lib \ node-jquery.js: 5: 39) on E: \ Sloppers bot \ node_modules \ jQuery \ lib \ node-jquery.js: 9435: 18 in the facility. (E: \ Sloppers bot \ node_modules \ jQuery \ lib \ node-jquery.js: 9437: 2) on Module._compile (module.js: 434: 26) in Object.Module._extensions..js (module.js: 452: 10) on Module.load (module.js: 355: 32) in Function.Module._load (module.js: 310: 12) on Module.require (module.js: 365: 17) on demand (module. js: 384: 17) in the object. (E: \ Sloppers bot \ bot.js: 2: 9)

What am I doing

this is for the bot i work

+6
source share
5 answers

jquery 3.2.1, jsdom 10.1.0. He works.

 const jsdom = require("jsdom"); const { JSDOM } = jsdom; const { window } = new JSDOM(`<!DOCTYPE html>`); const $ = require('jQuery')(window); $('<h1>Hello</h1>').appendTo('body'); console.log($('h1').text()); 
+10
source

I ran into the same problem, and now it’s fine after I changed the package from require('jQuery') to require('jQuery') . It appears that a later package ( jquery ) uses a newer version of jQuery than the previous one ( jquery ).

+7
source

I ran into the same problem, and during debugging I found out about something new.

When you do that -

 npm install jQuery 

It installs jQuery version 1.7.4 version into your project.

And when you do that -

 npm install jQuery 

It installs jQuery version 3.2.1 version into your project.

enter image description here

The difference between the two teams is just the uppercase Q. Therefore, if you get this error, you are probably using the old version of jQuery.

You can learn more about the first team (old version) here and the second team here .

+1
source

Yes Yes. jQuery expects to have a β€œwindow”, which is usually a browser-only object. Thus, the window needs to be modeled. This is what jsdom does.

After enabling jsdom ( npm install jsdom ):

 // Load jsdom, and create a window. var jsdom = require("jsdom").jsdom; var doc = jsdom(); var window = doc.defaultView; // Load jQuery with the simulated jsdom window. $ = require('jquery')(window); 

See the jsdom documentation for more information: https://www.npmjs.com/package/jsdom

0
source

nothing worked for me

my jquery version: 3.2.1

jsdom version: 10.1.0 finally found a solution:

 var myHtmlString = 'akkadsf lakuseh alhf lasudfa ls<p></p>'; function jQuery(doc){ const jsdom = require("jsdom"); const { JSDOM } = jsdom; const { window } = new JSDOM(); const JQ = require("jquery")(window)(`<html>${doc || ''}</html>`); } var $ = jQuery; // my html string: var text = $(myHtmlString).text(); 
0
source

All Articles