Skip to main content

no-nodejs-modules

Disallow importing Node.js built-ins via the node: protocol.

Targeted pattern scope

This rule checks import/export source strings across:

  • import ... from "..."
  • export ... from "..."
  • export * from "..."
  • dynamic import("...")

By default it disallows sources matching node:*.

What this rule reports

This rule reports source strings that match "node:*".

Why this rule exists

Some codebases standardize on unprefixed built-in specifiers (fs, path) for compatibility or stylistic consistency. This rule enforces that policy.

❌ Incorrect

import fs from "node:fs";

✅ Correct

import fs from "fs";

Behavior and migration notes

This rule reports only and does not provide an autofix.

Migration is generally mechanical: replace node:fs with fs, node:path with path, and so on.

Options

type Options = {
allow?: string[];
disallow?: string[];
};

Default:

{
"disallow": ["node:*"]
}

Additional examples

export { readFile } from "node:fs/promises";
// ❌ reported by default

const fsModule = await import("fs");
// ✅ valid with default settings

ESLint flat config example

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-nodejs-modules": "error",
},
},
];

When not to use it

Disable this rule if your codebase intentionally requires node:-prefixed imports.

Package documentation

Rule catalog ID: R034

Further reading

Adoption resources

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.