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

Viewed 74754

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

6 Answers

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().

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.

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

you can update node to ver 17, i solved my issue by this solution

for me helped run my project as node --trace-deprecation /var/www/my-script-path and open it webpage. after i read in console path to depricated code and it module name. for me it old version express.js. after upgrade it error is not show.

Related