n/prefer-node-protocol
April 30, 2026 ยท View on GitHub
๐ Enforce using the node: protocol when importing Node.js builtin modules.
๐ง This rule is automatically fixable by the --fix CLI option.
Older built-in Node modules such as fs now can be imported via either their name or node: + their name:
import fs from "fs"
import fs from "node:fs"
The prefixed versions are nice because they can't be overridden by user modules and are similarly formatted to prefix-only modules such as node:test.
Note that Node.js support for this feature began in:
v16.0.0, v14.18.0 (
require())
v14.13.1, v12.20.0 (import) v22.3.0, v20.16.0 (process.getBuiltinModule())
๐ Rule Details
This rule enforces that node: protocol is prepended to built-in Node modules when importing or exporting built-in Node modules.
๐ Examples of correct code for this rule:
/*eslint n/prefer-node-protocol: error */
import fs from "node:fs"
export { promises } from "node:fs"
const fs = require("node:fs")
const fs = process.getBuiltinModule("node:fs")
๐ Examples of incorrect code for this rule:
/*eslint n/prefer-node-protocol: error */
import fs from "fs"
export { promises } from "fs"
const fs = require("fs")
const fs = process.getBuiltinModule("fs")
Configured Node.js version range
Configured Node.js version range
Options
{
"n/prefer-node-protocol": ["error", {
"version": ">=16.0.0",
}]
}
version
As mentioned above, this rule reads the [engines] field of package.json.
But, you can overwrite the version by version option.
The version option accepts the valid version range of node-semver.