![](/img/trans.png)
[英]Node.js “Cannot read property 'prototype' of undefined” error - Node.js, MongoDB and Angularjs book
[英]Node.js with ExpressJS error: Cannot read property 'prototype' of undefined
运行node.js v0.10.2并表达v3.1.1(此时最新)并收到此错误:
/root/dmr-addresses/node_modules/jquery/lib/node-jquery.js:10
window.XMLHttpRequest.prototype.withCredentials = false;
^
TypeError: Cannot read property 'prototype' of undefined
at create (/root/dmr-addresses/node_modules/jquery/lib/node-jquery.js:10:26)
at /root/dmr-addresses/node_modules/jquery/lib/node-jquery.js:9503:18
at Object.<anonymous> (/root/dmr-addresses/node_modules/jquery/lib/node-jquery.js:9505: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> (/root/dmr-addresses/address/log.js:1:71)
log.js的第1行是:
var $ = require('jquery');
我试过运行npm install jquery
但它没有解决问题。
检查一下:
同样的错误......我不知道我在做什么,但是我改变了node-jquery.js第四和第五行 ,它开始工作了:)
旧:
if(window == null ) {
window = require('jsdom').jsdom().createWindow();
新:
if(!window || !window.document) {
window = require('jsdom').createWindow();
window.document = require('jsdom').jsdom();
你实际上在节点服务器代码中没有原型对象,它全部存储在更好的__ proto __对象中,你应该使用Object.create / defineProperty 。
你究竟想做什么? 使用Node运行ajax查询? 如果是这样,您应该使用节点http.request
一个例子可能是:
require('request').post({
"uri" : "http://example.com/",
"headers" : {
'content-type': 'application/json'
},
"body" : "hello=world"
},
function(e,r,b){
// e = errors, r = response and b = returned body
console.log(b,r.statusCode));
});
看起来这是node-jquery所依赖的jsdom模块的问题。 看来这是一个已知的问题,它已被修复,但尚未发布到npm。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.