How to fix (node:12388) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated in windows
Solution 1
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
Using node 12.0.0 I get the same error using http-server. Switching to 10.11.0 removes the error.
Solution 2
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()
.
Solution 3
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.
Solution 4
For those getting it everytime they start their project,
Run: npm i browser-sync
Gabriel Rogath
Java Programmer Android App Developer Web App Developer(Spring Boot and laravel)
Updated on June 11, 2021Comments
-
Gabriel Rogath almost 3 years
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
-
ciso almost 5 yearsFor future reference... per the link, as an example, instead of using obj._headers, use obj.getHeaders() to get the headers object. So replace the property name "._headers" with the function ".getHeaders()". Same results using either one except using the function is the supported method and removes the deprecation warning.
-
gnganapath about 4 yearsWhile working with angular micro front end application, I received the micro app not render inside master. After downgrade node js to 10.x it's working. thanks
-
Felix Aballi almost 4 yearsAlso, works with latest LTS v10 (lts/dubnium -> v10.22.0)
-
Mehedi over 3 yearsAlso, add
app.disable('x-powered-by')
to yourserver.js
file, aftervar app = express()
, to pass the test immediately or in single attempt.