nodejs / nodejs/userland-migrations

feat: handle DEP0187: Passing invalid argument types to `fs.existsSync`

Open
#178 6 comments 0 reactions 0 assignees View on GitHub

@techflare641 is already working on this.

Since Oct 9, 2025.

  • #231 by @techflare641 — open
good first issue human help wanted let's do it
Dominant language
TypeScript
Stars
85
Forks
55
Avg merge
3d 11h
Merged PRs (30d)
9

Description

Description

This codemod should validate and convert invalid argument types to fs.existsSync(). It's useful to migrate code that passes invalid argument types which now causes deprecation warnings or errors.

It should validate that fs.existsSync() receives string, Buffer, or URL arguments only. It should convert invalid argument types to valid ones where possible. It should handle both CommonJS and ESM imports. It should add type checks or conversions to ensure argument validity.

Examples

Case 1

Before:

const fs = require("node:fs");

const exists = fs.existsSync(123);

After:

const fs = require("node:fs");

const exists = fs.existsSync(String(123));
Case 2

Before:

const fs = require("node:fs");

function checkFile(path) {
  return fs.existsSync(path);
}

After:

const fs = require("node:fs");

function checkFile(path) {
  if (typeof path !== 'string' && !Buffer.isBuffer(path) && !(path instanceof URL)) {
    path = String(path);
  }
  return fs.existsSync(path);
}
Case 3

Before:

const fs = require("node:fs");

const fileExists = fs.existsSync(null);

After:

const fs = require("node:fs");

const fileExists = fs.existsSync(String(null || ''));
Case 4

Before:

import { existsSync } from "node:fs";

const exists = existsSync({ path: '/some/file' });

After:

import { existsSync } from "node:fs";

const exists = existsSync(String({ path: '/some/file' }));

REFS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked DEP0187 reference and the four examples in the issue, including both CommonJS and ESM forms. Done means invalid fs.existsSync arguments are validated or converted to supported string, Buffer, or URL values in each described case, with the existing open pull request indicating that work is already underway.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.