小编Exu*_*iax的帖子

将 JQuery 与 Node.js “ReferenceError: $ is not defined”一起使用

我正在尝试使用此框架在 Node.js 中为 Twitch 构建一个简单的 IRC 机器人https://github.com/Schmoopiie/twitch-irc,它可以连接到 API 并检查某些事情,在本参考中,我将检查机器人所在的当前频道上的关注者。除了我遇到错误之外,我一直在下面记录此错误。

[31mcrash[39m: ReferenceError: $ is not defined
    at client.<anonymous> (C:\Users\Exuviax\Desktop\node.js\bot.js:157:9)
    at client.emit (events.js:117:20)
    at C:\Users\Exuviax\Desktop\node.js\node_modules\twitch-irc\library\client.js:657:30
    at Object.createChannelUserData (C:\Users\Exuviax\Desktop\node.js\node_modules\twitch-irc\library\data.js:56:2)
    at client._handleMessage (C:\Users\Exuviax\Desktop\node.js\node_modules\twitch-irc\library\client.js:651:22)
    at Stream.emit (events.js:95:17)
    at drain (C:\Users\Exuviax\Desktop\node.js\node_modules\twitch-irc\node_modules\irc-message-stream\node_modules\through\index.js:36:16)
    at Stream.stream.queue.stream.push (C:\Users\Exuviax\Desktop\node.js\node_modules\twitch-irc\node_modules\irc-message-stream\node_modules\through\index.js:45:5)
    at LineStream.<anonymous> (C:\Users\Exuviax\Desktop\node.js\node_modules\twitch-irc\node_modules\irc-message-stream\index.js:22:16)
    at LineStream.emit (events.js:95:17)
Run Code Online (Sandbox Code Playgroud)

这是我用来运行的代码,以检查 API

var irc = require('twitch-irc');
var colors = require('colors');
var jQuery = require('jQuery')
var jsdom = require("jsdom");
var window = jsdom.jsdom().parentWindow;

jsdom.jQueryify(window, "http://code.jquery.com/jquery-2.1.3.min.js", function () {
  var $ = window.$;
  $("body").prepend("<h1>The title</h1>");
  console.log($("h1").html()); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery node.js referenceerror

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

javascript ×1

jquery ×1

node.js ×1

referenceerror ×1