jquery - 在 node.js 中使用 JQuery 时出错

标签 jquery node.js npm

我在 Windows 7 上全新安装了 node.js,我正在尝试运行一个非常基本的 JQuery 脚本,名为 a.js,其中仅包含:

require("jquery");
$().jquery;

不幸的是,这不会与 JQuery 一起运行,给我一个 TypeError:

C:\Users\Ian>node a.js

C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:10
    window.XMLHttpRequest.prototype.withCredentials = false;
                         ^
TypeError: Cannot read property 'prototype' of undefined
    at create (C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:10:26)
    at C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:9435:18
    at Object.<anonymous> (C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:9437:2)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (C:\Users\Ian\a.js:1:63)

我通过 Google 发现了一些关于此错误的错误报告,其中大部分建议降级 JQuery。但是,当我这样做时,我只会得到一个不同的错误。下面是 JQuery 1.6.3:

C:\Users\Ian>node a.js

module.js:340
    throw err;
      ^
Error: Cannot find module 'location'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at create (C:\Users\Ian\node_modules\jquery\node-jquery.js:6:33)
    at C:\Users\Ian\node_modules\jquery\node-jquery.js:9065:18
    at Object.<anonymous> (C:\Users\Ian\node_modules\jquery\node-jquery.js:9067:2)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)

任何人都可以提出什么可能是错的吗?我已经尝试过各种软件的重新安装,但没有成功。我已经为默认版本的 jquery 和 jquery@1.6.3 尝试了 npm install -gnpm install

编辑:This question - 尚未回答 - 似乎相关。

最佳答案

如果你在 Node 0.10.x 上...运行 sudo npm rebuild

https://github.com/coolaj86/node-jquery/issues/35

关于jquery - 在 node.js 中使用 JQuery 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12979531/

相关文章:

jenkins - 如何在 Jenkins 声明式管道的代理部分使用环境变量?

node.js - 如何收缩包装 devDependencies,但除非必要,否则不要安装它们?

javascript - 单击时,将类添加到行中的第一个 <td> 和表中相应的 <th>

javascript - 更改 <li> 内仅包含 <label> 标签的标签

javascript - 意外的字符串

javascript - nodejs、socket、https - Socket 不建立连接,仅断开连接

javascript回调闭包 undefined variable

node.js - Heroku 缺少模块

sql-server - nodejs 出现 mssql 连接超时错误

JQuery 获取所选 Kendo Treeview 的所有父节点