2015-04-21 46 views
0

我的Node.js應用程序在節點v10.29下運行正常。捕捉異常:錯誤:升級後在結束後寫入節點版本

,當「節點」的版本。

我升級的節點到12.0版本後,我開始一個Caught exception: Error: write after end錯誤:

Caught exception: Error: write after end at ServerResponse.OutgoingMessage.write (_http_outgoing.js:413:15) at ServerResponse.res.write (/home/node_app_name/node_modules/express/node_modules/connect/lib/middleware/compress.js:110:17) at ServerResponse.res.end (/home/node_app_name/node_modules/express/node_modules/connect/lib/middleware/compress.js:116:14) at ServerResponse.res.send (/home/node_app_name/node_modules/express/lib/response.js:152:8) at /home/node_app_name/models/file_name.js:1205:61 at /home/node_app_name/node_modules/mongoose/lib/utils.js:414:16 at /home/node_app_name/node_modules/mongoose/node_modules/mongodb/lib/mongodb/collection.js:497:9 at Server.Base._callHandler (/home/node_app_name/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:382:41) at /home/node_app_name/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:472:18 at MongoReply.parseBody (/home/node_app_name/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)

Caught exception: Error: write after end at ServerResponse.OutgoingMessage.write (_http_outgoing.js:413:15) at ServerResponse.res.write (/home/node_app_name/node_modules/express/node_modules/connect/lib/middleware/compress.js:110:17) at ServerResponse.res.end (/home/node_app_name/node_modules/express/node_modules/connect/lib/middleware/compress.js:116:14) at ServerResponse.res.send (/home/node_app_name/node_modules/express/lib/response.js:154:8) at fn (/home/node_app_name/node_modules/express/lib/response.js:794:10) at View.exports.renderFile [as engine] (/home/node_app_name/node_modules/jade/lib/jade.js:222:12) at View.render (/home/node_app_name/node_modules/express/lib/view.js:76:8) at Function.app.render (/home/node_app_name/node_modules/express/lib/application.js:504:10) at ServerResponse.res.render (/home/node_app_name/node_modules/express/lib/response.js:798:7) at Request._callback (/home/node_app_name/app/controllers/file_name.js:92:16)

我尋覓了很多關於上述錯誤,但我仍然不能夠得到有效的解決方案吧。

什麼是導致此錯誤,我該如何解決它?

回答

1

如果您正在使用res.send(...); (在路徑代碼app.get('path',function(req,res){});)中的代碼中不止一次。將其改爲res.write(....);

+0

ThnQ Rahaman,您的回覆,但我不使用res.send超過在同一航線代碼塊一次,我用它只有一次, 除此之外, 爲節點是異步的,一旦資源被髮送是res.send(),我甚至用res.end()結束響應,並通過編寫「return;」從該代碼塊返回。以及 – gehlotparesh

1

我想你應該把response.end();在聲明路徑的每一端(「/」或「/ etc」)中。