express icon indicating copy to clipboard operation
express copied to clipboard

DeprecationWarning: OutgoingMessage.prototpye._headers is deprecated

Open SebastianBoehler opened this issue 6 years ago • 11 comments

Everything works fine until it should return the response.

this error message is displayed: DeprecationWarning: OutgoingMessage.prototpye._headers is deprecated

SebastianBoehler avatar May 11 '20 17:05 SebastianBoehler

What version of Express are you using? This was an issue but resolved a while back, so maybe just outdated Express version being used.

dougwilson avatar May 11 '20 17:05 dougwilson

v 4.17.1

It works fine on my local machine, only getting this error on my Ubuntu server Node version: 12.16.3

SebastianBoehler avatar May 11 '20 17:05 SebastianBoehler

Hmm.. I searched through the code and don't see it being used anywhere. Can you provide a stack trace for the deprecation? https://nodejs.org/dist/latest-v14.x/docs/api/cli.html#cli_trace_deprecation

dougwilson avatar May 11 '20 17:05 dougwilson

Hey didn't exactly got what to do.

got something like that when loading my file: settings: { 'x-powered-by': true, etag: 'weak', 'etag fn': [Function: generateETag], env: 'development', 'query parser': 'extended', 'query parser fn': [Function: parseExtendedQueryString], 'subdomain offset': 2, 'trust proxy': false, 'trust proxy fn': [Function: trustNone], view: [Function: View], views: 'C:\\Users\\Basti\\Desktop\\ticket-api\\views', 'jsonp callback name': 'callback' }, locals: [Object: null prototype] { settings: { 'x-powered-by': true, etag: 'weak', 'etag fn': [Function: generateETag], env: 'development', 'query parser': 'extended', 'query parser fn': [Function: parseExtendedQueryString], 'subdomain offset': 2, 'trust proxy': false, 'trust proxy fn': [Function: trustNone], view: [Function: View], views: 'C:\\Users\\Basti\\Desktop\\ticket-api\\views', 'jsonp callback name': 'callback' } }, mountpath: '/', _router: [Function: router] { params: {}, _params: [], caseSensitive: false, mergeParams: undefined, strict: false, stack: [ [Layer], [Layer], [Layer], [Layer] ] } }

SebastianBoehler avatar May 12 '20 16:05 SebastianBoehler

It is likely introduced by another package, some middleware perhaps, or even an older version of node-fetch.

A reproduction case would be best, but posting your list of dependencies might help as well. If you get a chance, can you post the output of the following commands run from your project's folder? It will give us an idea of the dependencies you're using.

npm ls --depth=0
npm outdated

Thanks!

jonchurch avatar May 12 '20 20:05 jonchurch

My code: https://pastebin.com/wdRrw77z Works fine on local machine but not on ubuntu server as already mentioned.

Dependencies: "dependencies": { "body-parser": "^1.19.0", "cheerio": "^1.0.0-rc.3", "express": "^4.17.1", "fs": "0.0.1-security", "node-fetch": "^2.6.0", "universal-analytics": "^0.4.20", "wasm2js": "^0.2.0" }

npm ls --depth=0 returns +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] -- [email protected]

npm outdated returns nothing

SebastianBoehler avatar May 12 '20 20:05 SebastianBoehler

I was able to run the script on my server by using res.send(data) instead of res.json(data)

SebastianBoehler avatar May 13 '20 14:05 SebastianBoehler

Hmm very strange. I'd suggest double checking what version of Express is running in production, maybe there's an old package-lock.json sticking around on the prod server that is forcing an outdated Express version? That's one possibility I can think of.

res.json still uses res.send under the hood, and both use the same res.set to set headers, so I'm not sure at all why the issue would be solved using res.send.

jonchurch avatar May 13 '20 14:05 jonchurch

Hey @SebastianBoehler!

Has the issue been resolved for you? Or do you still face the issue. If yes, please provide a MCVE for us to take a look at. If not, you can close this issue.

aravindvnair99 avatar Apr 21 '21 13:04 aravindvnair99

Closing stale issue.

dougwilson avatar May 08 '21 05:05 dougwilson

For my case issue is not related to express. http.ServerResponse is node.js class, could be any other package using it. To debug:

process.on('warning', (warning) => {
    console.log(warning.stack);
});

My output:

(Use `node --trace-deprecation ...` to show where the warning was created)
DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
    at Test.Request._redirect (/Users/<user>/<my-app>/node_modules/superagent/lib/node/index.js:419:26)

npm ls --depth=2 | grep 'chai\|super'

├─┬ [email protected]
│ └─┬ [email protected]

Shameness avatar Dec 08 '21 12:12 Shameness