no-nodejs-modules
Added in v0.9.4Configuration
Rule Details
Disallow Node.js builtin modules in code that runs without Node.js, such as a browser application.
The rule checks static imports, re-exports, dynamic import() calls, and
single-argument require() calls with string literals. Explicit type imports
and re-exports are also checked. It reports the entire declaration or call and
does not provide automatic fixes or suggestions.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
allow is an array of allowed module names. It defaults to [] and matches
the complete specifier exactly: allowing fs does not allow node:fs or
fs/promises.
The rule respects import/core-modules, import/internal-regex, and
import/resolver settings. An internal regular-expression match takes
precedence over builtin classification. A package subpath counts as builtin
when its package root is builtin or configured as core, unless the subpath
resolves to a project file. import/ignore does not suppress this rule.
Differences from upstream
import/resolver supports node and typescript. Other resolvers, such as
webpack, produce a resolver error. For projects with aliases, select
typescript and define the aliases in your tsconfig.json.
Select the TypeScript project with languageOptions.parserOptions.project.
For example, use project: ['./tsconfig.app.json'] there;
settings['import/resolver'].typescript.project does not select a project.
If you use multiple resolvers and need a particular order, list them in an
array, such as ['typescript', 'node'].
The _stream_* modules removed in Node.js 26, such as _stream_readable, are
not reported unless listed in import/core-modules. ESLint running on older
Node.js versions may still report them as builtins.
When Not To Use It
Disable this rule for code that runs in Node.js and may use its builtin modules.