将JQuery与node.js一起使用时出错 [英] Errors using JQuery with node.js

查看:77
本文介绍了将JQuery与node.js一起使用时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a fresh install of node.js running on Windows 7, and I am trying to run a very basic JQuery script, named a.js, which contains just:

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

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

Unfortunately, this will not run with JQuery, giving me a 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:

I have found a few bug reports on this error through Google, most of which suggest downgrading JQuery. However, when I do that, I just get a different error. The below is with 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)

任何人都可以建议出什么问题吗?我已经尝试过各种软件的重新安装,但是没有运气.我已经尝试使用npm install -gnpm install来设置默认版本的jquery和jquery@1.6.3.

Can anyone suggest what may be wrong? I have tried various reinstallations of the software with no luck. I have tried both npm install -g and npm install for both the default version of jquery and also jquery@1.6.3.

这个问题-尚未解答-似乎相关.

This question - as yet unanswered - seems related.

推荐答案

如果节点0.10.x上的ur ...运行sudo npm rebuild

If ur on node 0.10.x ... run sudo npm rebuild

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

这篇关于将JQuery与node.js一起使用时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆