suchen

Heim  >  Fragen und Antworten  >  Hauptteil

node.js – Meldet Node+Express einen Fehler, wenn Chrome den Debug-Modus öffnet?

_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


Wenn Sie den Debugging-Modus nicht starten, tritt beim Laden der Seite kein Fehler auf, req und res sind alle normal

某草草某草草2747 Tage vor966

Antworte allen(1)Ich werde antworten

  • 欧阳克

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

    代码写的有问题,跟调试模式无关,response响应已经被发送了,但是你却仍然想修改已经被发送的响应头。
    一旦调用 response.end() 方法,代表此响应已经结束并发送,在此之后不得调用诸如 response.writeHead() 等修改 response 的方法。

    Antwort
    0
  • StornierenAntwort