馃摑 Enforce using process.getBuiltinModule() to load Node.js built-in modules.
Node.js exposes built-in modules synchronously through process.getBuiltinModule().
In ES modules, this avoids creating a require function solely to access a
built-in module. It also communicates that the requested module is built into
Node.js.
This API is available starting in Node.js 20.16.0 on the 20.x release line and in Node.js 22.3.0 or later.
This rule reports calls to require() for built-in modules and awaited dynamic
imports of built-in modules. It ignores non-built-in modules, dynamic imports
that are not awaited directly, arbitrary functions named require, and
references where process is shadowed. A local require created with
createRequire() from node:module is recognized.
This rule is not automatically fixable. An awaited dynamic import returns an
ES module namespace object, while process.getBuiltinModule() returns the
underlying built-in exports object. Review how the loaded module is used when
applying the suggested replacement.
馃憤 Examples of correct code for this rule:
/*eslint n/prefer-process-get-builtin-module: error */
const fs = process.getBuiltinModule("node:fs")
const eslint = require("eslint")
const lazyFs = import("node:fs")馃憥 Examples of incorrect code for this rule:
/*eslint n/prefer-process-get-builtin-module: error */
const fs = require("node:fs")
const promises = await import("node:fs/promises")Configured Node.js version range
{
"n/prefer-process-get-builtin-module": [
"error",
{
"version": ">=22.3.0"
}
]
}This rule reads the [engines] field of package.json. You can override that
range with the version option, which accepts any valid
node-semver range.
The rule does not report when the configured range includes Node.js versions
without process.getBuiltinModule().