dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.72k stars 166 forks source link

Nodejs 12: ERROR (node:8) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated #130

Closed bsdkurt closed 4 years ago

bsdkurt commented 4 years ago

Using aws lambda nodejs12.x runtime with serverless-http 2.3.0 generates the following warning:

ERROR   (node:8) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated

Presumably due to the use of _headers in libs/response.js.

kevinmarrec commented 4 years ago

Seems to have been declared as depreciation since Node.js 8 (documentation-only) : https://nodejs.org/api/deprecations.html#deprecations_dep0066_outgoingmessage_prototype_headers_outgoingmessage_prototype_headernames

The OutgoingMessage.prototype._headers and OutgoingMessage.prototype._headerNames properties were never documented as officially supported properties.

The above link says that OutgoingMessage.prototype.getHeaders(), OutgoingMessage.prototype.setHeader() should be used instead.

psrijay commented 4 years ago

Node version: v12.18.0 I am getting the same issue. http://localhost:3000/index.html is blank even after log files are generated

MehediEhteshum commented 3 years ago

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

harshpatel1242 commented 2 years ago

npm i browser-sync

try to run this ,it worked for me.

eshnish commented 1 year ago

I still have the same issue and I am unable to find the server.js file in node. node: v18.12.1 OS: Win 10 Pro http-server: v14.1.1

(node:12892) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated (Use node --trace-deprecation ... to show where the warning was created)