首頁  >  問答  >  主體

node.js - node+express 在chrome開啟偵錯模式時會報錯?

_http_outgoing.js:504
    throw new Error('Can\'t set headers after they are sent.');
    ^

Error: Can't set headers after they are sent.
    at validateHeader (_http_outgoing.js:504:11)
    at ServerResponse.setHeader (_http_outgoing.js:511:3)
    at Array.write (D:\GitSpace\fbms\node_modules\_finalhandler@1.0.3@finalhandl
er\index.js:254:9)
    at listener (D:\GitSpace\fbms\node_modules\_on-finished@2.3.0@on-finished\in
dex.js:169:15)
    at onFinish (D:\GitSpace\fbms\node_modules\_on-finished@2.3.0@on-finished\in
dex.js:100:5)
    at callback (D:\GitSpace\fbms\node_modules\_ee-first@1.1.1@ee-first\index.js
:55:10)
    at IncomingMessage.onevent (D:\GitSpace\fbms\node_modules\_ee-first@1.1.1@ee
-first\index.js:93:5)
    at emitNone (events.js:105:13)
    at IncomingMessage.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1045:12)
    at _combinedTickCallback (internal/process/next_tick.js:102:11)
    at process._tickCallback (internal/process/next_tick.js:161:9)
Program node app.js exited with code 1


如果不啟動偵錯模式就不會有這個報錯,頁面載入和req,res都正常

某草草某草草2685 天前906

全部回覆(1)我來回復

  • 欧阳克

    欧阳克2017-07-06 10:37:27

    程式碼寫的有問題,跟調試模式無關,response回應已經被傳送了,但是你卻還是想修改已經被傳送的回應頭。
    一旦呼叫 response.end() 方法,代表此回應已經結束並傳送,在此之後不得呼叫諸如 response.writeHead() 等修改 response 的方法。

    回覆
    0
  • 取消回覆