Node.js Jsdom返回[错误:套接字挂起]代码:'ECONNRESET'}

时间:2013-02-21 00:14:31

标签: node.js jsdom

尝试在nodejs下使用jsdom并收到此错误:

[错误:套接字挂断]代码:'ECONNRESET'}

使用NodeJs v0.8.20,Ubuntu 12.04

   var jsdom = require("jsdom");
    jsdom.env({
                    html: 'http://www.google.com',
                    scripts: ['http://code.jquery.com/jquery.js'],
                    done: function (errors, window) { console.log(errors); }
   });

2 个答案:

答案 0 :(得分:1)

http://clock.co.uk/tech-blogs/preventing-http-raise-hangup-error-on-destroyed-socket-write-from-crashing-your-nodejs-server

基本上有一个错误,其中套接字挂起错误被抑制,但在节点0.8.20中它不再被抑制。但是,大多数模块还没有收听该错误事件。

所以......降级你的node.js版本并等到jsdom修复它,或者使用域名。非常肯定问题是jsdom使用旧版本的请求。或者你可以不使用JSDOM的HTTP部分。

答案 1 :(得分:0)

这意味着另一方意外关闭了连接。

当我尝试运行您的脚本时,我明白了:

/Users/isaacs/dev/js/x/node_modules/jsdom/lib/jsdom.js:178
    features   = JSON.parse(JSON.stringify(window.document.implementation._fea
                                                          ^
TypeError: Cannot read property 'implementation' of undefined
    at exports.env.exports.jsdom.env.processHTML (/Users/isaacs/dev/js/x/node_modules/jsdom/lib/jsdom.js:178:59)
    at Request.exports.env.exports.jsdom.env [as _callback] (/Users/isaacs/dev/js/x/node_modules/jsdom/lib/jsdom.js:283:9)
    at Request.init.self.callback (/Users/isaacs/dev/js/x/node_modules/jsdom/node_modules/request/main.js:127:22)
    at Request.EventEmitter.emit (events.js:99:17)
    at Request.<anonymous> (/Users/isaacs/dev/js/x/node_modules/jsdom/node_modules/request/main.js:767:16)
    at Request.EventEmitter.emit (events.js:126:20)
    at IncomingMessage.Request.start.self.req.self.httpModule.request.buffer (/Users/isaacs/dev/js/x/node_modules/jsdom/node_modules/request/main.js:729:14)
    at IncomingMessage.EventEmitter.emit (events.js:126:20)
    at IncomingMessage._emitEnd (http.js:366:10)
    at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23)