Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix (node:12388) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated in windows

I am new to nodes.I have install nosejs version v12.4.0, npm 6.9.0 , http-server 0.11.1 and visual studio code.I want to open my hello word project with my http-server,it is in Visual studio code. But I receive the below error

ERROR

[2019-06-21T05:20:18.280Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" (node:11596) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated

I tried npm install node-gyp to fix the header problem but no success.

Also I have try to use different browsers eg. chrome, firefox , explore but no success.

    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
        <h1> Hello Word </h1>
    </body>
    </html>

I expected to see "Hello Word" in any of the browsers.I am using windows 10. Kindly assist

like image 515
Gabriel Rogath Avatar asked Jun 21 '19 05:06

Gabriel Rogath


4 Answers

Node version 12 depracated OutgoingMessage.prototype._headers, which is used in http-server. Issue is listed at: https://github.com/http-party/http-server/issues/537

https://nodejs.org/api/deprecations.html#deprecations_dep0066_outgoingmessage_prototype_headers_outgoingmessage_prototype_headernames

Using node 12.0.0 I get the same error using http-server. Switching to 10.11.0 removes the error.

like image 133
ch1pn3ss Avatar answered Sep 21 '22 05:09

ch1pn3ss


Those who are facing this problem in FreeCodeCamp exercise, the issue is in the server.js file. The solution is to replace ._headers with .getHeaders(), as the error is telling us that ._headers has been deprecated. e.g. in server.js, instead of -

// filter out CORS Headers
var hs = Object.keys(res._headers)
  .filter(h => !h.match(/^access-control-\w+/));
var hObj = {};
hs.forEach(h => {hObj[h] = res._headers[h]});
delete res._headers['strict-transport-security'];

use the following -

// filter out CORS Headers
var hs = Object.keys(res.getHeaders())
  .filter(h => !h.match(/^access-control-\w+/));
var hObj = {};
hs.forEach(h => {hObj[h] = res.getHeaders()[h]});
delete res.getHeaders()['strict-transport-security'];

Summary: replace all ._headers with .getHeaders().

like image 33
Mehedi Avatar answered Sep 20 '22 05:09

Mehedi


I had some issue with browser-sync. When I started project I got warning from node ([DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated) every time. But when I updated my browser-synk dependencies to "browser-sync": "^2.26.13" my project started without any warning.

like image 23
Dmytro Kukharuk Avatar answered Sep 19 '22 05:09

Dmytro Kukharuk


For those getting it everytime they start their project, Run: npm i browser-sync

like image 24
Ritika Gupta Avatar answered Sep 19 '22 05:09

Ritika Gupta