Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs jQuery needs jsdom

$.getJSON('https://api.twitch.tv/kraken/channels/' + SLoppierKitty7, function(channel) {

if (channel["stream"] == null) { 
    var live ="no"

} else {

      var live ="yes"

}

that 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 at create (E:\Sloppers bot\node_modules\jQuery\lib\node-jquery.js:5:39) at E:\Sloppers bot\node_modules\jQuery\lib\node-jquery.js:9435:18 at Object. (E:\Sloppers bot\node_modules\jQuery\lib\node-jquery.js:9437:2) at Module._compile (module.js:434:26) at Object.Module._extensions..js (module.js:452:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) at require (module.js:384:17) at Object. (E:\Sloppers bot\bot.js:2:9)

what do i do

this is for a bot i'm working

like image 323
SloppierKitty7 Avatar asked May 15 '16 14:05

SloppierKitty7


2 Answers

I encountered the same problem, and it is OK now after I changed the package from require('jQuery') to require('jquery'). It seems that the later package (jquery) use a more recent version of jQuery than the former one (jQuery).

like image 32
realjin Avatar answered Sep 28 '22 00:09

realjin


jquery 3.2.1, jsdom 10.1.0. It 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());
like image 200
sutara79 Avatar answered Sep 28 '22 00:09

sutara79