Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

DEP0066: code that reads res._headers breaks on current Node.js

Error[DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated

Short answer

DEP0066 covers the undocumented properties _headers and _headerNames on OutgoingMessage, such as res._headers. Node.js lists them as End-of-Life, so code that reads them must switch to the public methods: getHeaders(), getHeader(), getHeaderNames(), hasHeader(), setHeader() and removeHeader().

  • Applies to Node.js 22, Node.js 24
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the app with --throw-deprecation. Node then throws at the first use, and the stack trace shows whether your code or a dependency reads the property.

    node --throw-deprecation server.js
  2. 2Match what you see, then jump to its fix

    1. 1The stack trace points to a file in your projectYour own code reads res._headers or res._headerNamesFix
    2. 2The stack trace points into node_modulesAn old dependency reads the propertyFix
    3. 3The warning is hidden with --no-deprecation but the code still uses the propertySilencing the warning instead of fixing the codeFix

What does the error look like?

  • [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated

Cause 1 of 3

Your own code reads res._headers or res._headerNames

1Check

The Node.js deprecation list says these properties were never documented as supported, and names the public methods to use instead.

grep -rn "_headers\|_headerNames" src/ lib/ app.js server.js 2>/dev/null

2Fix

Replace each use with the public method that fits.

// before
const type = res._headers['content-type'];
// after
const type = res.getHeader('content-type');
const all = res.getHeaders();
const names = res.getHeaderNames();

3Verify

Start the app with --throw-deprecation and make a request: no error.

node --throw-deprecation server.js

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

An old dependency reads the property

1Check

Find which package owns the file in the trace and which version is installed.

npm ls --all | grep -i "<package-name>"
npm outdated

2Fix

Update the package to a release that no longer uses the property, or replace it. The deprecation list marks the property End-of-Life, so waiting is not a plan.

npm install <package-name>@latest

3Verify

Run again with --throw-deprecation and exercise the route that failed.

node --throw-deprecation server.js

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

Silencing the warning instead of fixing the code

1Check

--no-deprecation only silences deprecation warnings. It does not restore removed behaviour.

grep -rn "no-deprecation" package.json Dockerfile ecosystem.config.js 2>/dev/null

2Fix

Remove the flag once the code uses public methods, so future deprecations stay visible.

# package.json
"start": "node server.js"

3Verify

A clean start shows no DEP warning.

node server.js

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Run tests with --throw-deprecation so a deprecated call fails CI.
  • Only use the documented methods of http.ServerResponse.
  • Keep dependencies current and read the Node.js deprecation list when you raise the Node.js major version.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.