# Fix "[DEP0147] DeprecationWarning: fs.rmdir(path, { recursive: true }) will be removed" in Node.js

Yes. An agent replaces recursive fs.rmdir() with fs.rm(), and checks the cases where the two differ: a missing path and a path that is a file.

[Run this on Rush](https://cloud.getrush.ai/run/fix-fs-rmdir-recursive-deprecation-warning/nodejs/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

Node.js printed this warning for years: `In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead`. The Node.js deprecation list records the steps. The option was deprecated in documentation in 14.14.0, the same release that added `fs.rm`. The warning became a runtime one in 16.0.0. In 25.0.0 the entry is marked End-of-Life, with the text that the `recursive` option of `fs.rmdir`, `fs.rmdirSync` and `fs.promises.rmdir` has been removed. A script that relied on it no longer deletes a directory that has files in it. The warning is the last notice before a build step stops cleaning up after itself.

HashLips/generative-art-node, an image generator with one dependency, has the typical call. `buildSetup` in `src/main.js` checks `fs.existsSync(buildDir)`, runs `fs.rmdirSync(buildDir, { recursive: true })` and then `fs.mkdirSync(buildDir)`. `index.js` calls it first on every `npm run build`, and the script then writes one PNG per edition and `_metadata.json` into that directory. On a Node.js release that still honours the option, each build prints the warning and works. Where the option is gone, the call behaves as a plain `rmdirSync` on a directory full of images, and a plain `rmdirSync` refuses a non-empty directory with `ENOTEMPTY`. The first build in a fresh clone passes, because no `build` directory exists yet. The second fails, which makes it look intermittent.

The agent replaces the call with `fs.rmSync(buildDir, { recursive: true, force: true })`, the form the deprecation entry recommends, and removes the `existsSync` guard that `force` makes unnecessary. It does not treat the two functions as the same, because they are not. Without `force`, `fs.rm` on a missing path throws `ENOENT`. With `force`, it is silent. And `fs.rm` deletes a path that turns out to be a regular file, where the old call threw `ENOTDIR`. For a build directory that is the behaviour you want. For a call whose path comes from user input or an environment variable, it widens what the line can delete, so the agent lists where each path comes from. Here `buildDir` is built from `process.env.PWD`, falling back to `process.cwd()`, plus a fixed `/build`.

It searches for all three spellings, `fs.rmdir`, `fs.rmdirSync` and `fs.promises.rmdir`, and ignores calls without the option, which are unaffected. Because `package.json` has no `engines` field and its `test` script is the npm placeholder, nothing states which Node.js versions the project supports or checks them. The agent says which versions it ran the build on, runs it twice in a row on each so the non-empty case is exercised, and proposes an `engines` entry of at least 14.14.0, the first release with `fs.rm`. The project's one dependency, `canvas`, is a native module, and the agent reports whether it installed from a prebuilt binary on each version or had to compile.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "This project prints \"[DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed\" or fails to clean a directory on a newer Node.js. Find every call to fs.rmdir, fs.rmdirSync, fs.promises.rmdir and any rmdir imported from fs or fs/promises that passes a recursive option, in source, scripts and build tooling. Ignore calls without the option. For each call, record where the path comes from (a constant, a config value, an environment variable, user input) and whether the code assumes the path exists. Replace each with the matching fs.rm, fs.rmSync or fs.promises.rm call using { recursive: true, force: true }, and remove existence checks that force makes redundant. Where the old code relied on an error for a missing path, keep that by leaving force off, and say so. Note for each call that fs.rm also deletes a regular file where rmdir would have thrown, and flag any call whose path is not fixed by the program. Then verify: install dependencies, and run the project's build or clean script twice in a row on the oldest Node.js version the project supports and on the newest release available, running with --throw-deprecation on the versions that still warn, so any remaining deprecated call fails loudly. If package.json has no engines field, propose one whose minimum is at least 14.14.0. Report any native dependency that failed to install on a version you tried. Open a pull request with each call, its replacement, and the commands and output from both runs on each version.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request that changes the listed calls and, if the agent proposed one, adds an `engines` field. For the image generator that is one function, reduced to two calls. The description has a row per call with the source of its path and the option set chosen, then the output of two consecutive builds on each Node.js version tried. The second build is the one that matters, since it is the run that finds a directory already full.

A reviewer reads the path column. A recursive, forced delete on a fixed subdirectory of the project is safe. One on a path assembled from an environment variable deserves a second look, and the description points at any such call instead of leaving it to be found. They also check that no call lost an error it depended on: code that used a failed `rmdir` to detect a missing directory behaves differently once `force` is set. If a native dependency would not install on the newest Node.js, the description says the build could not be verified there, and names the dependency.

## Run it on every GitHub issue labelled deprecation

Deprecation warnings get reported as issues long before anyone schedules them. Add an automation on the Project with a `github` trigger on `issues.labeled`, set its `labels` to the label your team puts on such reports, and save the prompt above. When an owner, member or collaborator adds the label, a run starts with the issue after the prompt, so a warning code pasted into the issue reaches the agent as event text.

For many small repositories, a server-side script can loop over them and send this request once per repository with an API key. A key runs at most its `max_concurrent` runs at once; the rest are created `queued` and start as slots free, so the loop needs no retry logic.

## Why run it on Rush?

Whether this change works depends on the Node.js release, and a developer has one on their machine. The agent installs several in its sandbox and runs the same build twice on each, starting from a clean checkout so the first-run and second-run cases are both real. The output of each run is kept with the session. That is how the pull request can show the build passing on a release where the option no longer exists, instead of asserting it.

It is also a job that is small in each repository and tedious across many. Deleting and recreating an output directory is a common first step in build scripts, so the same call tends to sit in every repository a team owns. Runs are independent and each has its own machine, so a team can start one per repository and review the pull requests as they come back, each with its own evidence.

## Frequently asked questions

### What is the replacement for fs.rmdirSync(dir, { recursive: true })?

`fs.rmSync(dir, { recursive: true, force: true })`. The asynchronous forms are `fs.rm` with a callback and `fs.promises.rm`. `force: true` makes a missing path a no-op, which is what most cleanup code wants.

### Do I still need the fs.existsSync check before it?

Not with `force: true`. Checking first and deleting second also leaves a gap in which another process can remove the directory, so dropping the check is slightly more robust as well as shorter.

### Which Node.js versions have fs.rm?

14.14.0 and later. The Node.js deprecation list dates the documentation-only deprecation of the recursive `rmdir` option to that same release. A project that must run on something older needs a small fallback or a dependency for this one call.

### Is plain fs.rmdir deprecated too?

No. Removing an empty directory with `fs.rmdir(path)` is unchanged. Only the `recursive` option is affected, and the agent leaves calls without it alone.

### Is there an automated migration?

The Node.js deprecation entry links a codemod, run with `npx codemod@latest @nodejs/rmdir`. The agent can use it for the mechanical rewrite and still does the parts a codemod does not: classifying where each path comes from and running the build twice per version.

## More Node.js jobs

- [Fix the punycode Deprecation Warning (DEP0040) in a Node.js Project](https://getrush.ai/run/fix-punycode-deprecation-warning/nodejs/)
- [Fix "[DEP0169] DeprecationWarning: url.parse() behavior is not standardized"](https://getrush.ai/run/fix-url-parse-deprecation-warning/nodejs/)
- [Fix Vulnerable Dependencies in a Node.js App](https://getrush.ai/run/fix-vulnerable-dependencies/nodejs/)

## More jobs like this: Turn a Linear label into a PR

- [Fix "AttributeError: 'HTMLParser' object has no attribute 'unescape'" in Python 3.9+](https://getrush.ai/run/fix-htmlparser-unescape-attribute-error/html-parser/)
- [Fix "AttributeError: module 'platform' has no attribute 'linux_distribution'"](https://getrush.ai/run/fix-platform-linux-distribution-attribute-error/platform/)
- [Fix "AttributeError: module 'plistlib' has no attribute 'readPlist'" in Python 3.9+](https://getrush.ai/run/fix-plistlib-readplist-attribute-error/plistlib/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
