Maaz Zindani

Loading the index…

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

Node.js prints a DEP0180 warning about the fs.Stats constructor

Error[DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.

Short answer

Node.js 22 warns when something calls new fs.Stats() or Stats() directly, because that class is internal. Stats objects are meant to come from fs.stat and its relatives. The call usually sits in a dependency. Run Node with --trace-deprecation to see the file, then update that package, change your own call, or silence just this code.

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

Fix it fast

  1. 1Find out which cause you have

    Print the stack for the warning. The first frame outside Node's own files names the package or file that makes the call.

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

    1. 1The stack trace points into a folder under node_modules, and none of your own files appearA dependency constructs fs.Stats itselfFix
    2. 2The first frame in the trace is one of your filesYour own code or a test helper calls new fs.Stats()Fix
    3. 3The program exits with an error that carries the DEP0180 text, instead of only printing a warningThe process stops because deprecations are set to throwFix

What does the error look like?

  • [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.

Cause 1 of 3

A dependency constructs fs.Stats itself

1Check

Node.js turned this into a runtime warning in v22.0.0. A package written for older versions, which called the constructor, now triggers it. Find who depends on that package.

node --version
npm ls <package-from-the-stack>

2Fix

Update the package that appears in the stack, or the parent package that pulls it in, to a release that no longer calls the constructor. Read its changelog for the word Stats or DEP0180.

npm update <package-from-the-stack>

3Verify

Run the same command again; the warning is gone.

node --trace-deprecation app.js

Confirmed by nodejs.org

Did this fix it?

Cause 2 of 3

Your own code or a test helper calls new fs.Stats()

1Check

Node.js documents that Stats objects are not meant to be created with new. They are the objects returned by fs.stat(), fs.lstat(), fs.fstat() and their synchronous versions.

grep -rn "new fs.Stats\|new Stats\|fs.Stats(" --include=*.js --include=*.ts --include=*.mjs --exclude-dir=node_modules .

2Fix

Get the object from a real stat call instead of building one.

import { statSync } from 'node:fs';

const stats = statSync('./package.json');
console.log(stats.isFile(), stats.size);

3Verify

The warning no longer appears when the code path runs.

node --trace-deprecation app.js

Confirmed by nodejs.org

Did this fix it?

Cause 3 of 3

The process stops because deprecations are set to throw

1Check

The --throw-deprecation flag turns deprecation warnings into thrown errors. It can arrive from the command line or through NODE_OPTIONS in a CI job.

echo "$NODE_OPTIONS"
grep -rn "throw-deprecation" package.json .github 2>/dev/null

2Fix

Fix the caller as in the two causes above. While you wait for a dependency release, silence only this code, so every other deprecation still shows.

node --disable-warning=DEP0180 app.js

# or for the whole job
export NODE_OPTIONS="--disable-warning=DEP0180"

3Verify

The command runs to the end and other deprecation warnings still print.

node --disable-warning=DEP0180 app.js

Confirmed by nodejs.org

Did this fix it?

How do I stop it coming back?

  • Treat the warning as a to-do item for the dependency, and track it in your upgrade notes instead of hiding all warnings with --no-deprecation.
  • Run your tests on the Node.js version you deploy, so a new runtime deprecation shows up in CI, not in production logs.
  • Keep lock files fresh with a regular update of dependencies, so packages written for older Node.js versions get replaced.

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.