Skip to content

noNodejsModules

¥Summary

¥How to configure

biome.json
{
"linter": {
"rules": {
"correctness": {
"noNodejsModules": "error"
}
}
}
}

¥Description

禁止使用 Node.js 内置模块。

¥Forbid the use of Node.js builtin modules.

这对于无法访问这些模块的客户端 Web 项目很有用。

¥This can be useful for client-side web projects that don’t have access to those modules.

如果 package.json 中声明的依赖与内置 Node.js 模块的名称匹配,则也不会触发该规则。

¥The rule also isn’t triggered if there are dependencies declared in the package.json that match the name of a built-in Node.js module.

忽略仅类型的导入。

¥Type-only imports are ignored.

¥Examples

¥Invalid

import fs from "fs";
code-block.js:1:16 lint/correctness/noNodejsModules ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Using Node.js modules is forbidden.

> 1 │ import fs from “fs”;
^^^^
2 │

Can be useful for client-side web projects that do not have access to those modules.

Remove the import module.

import path from "node:path";
code-block.js:1:18 lint/correctness/noNodejsModules ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Using Node.js modules is forbidden.

> 1 │ import path from “node:path”;
^^^^^^^^^^^
2 │

Can be useful for client-side web projects that do not have access to those modules.

Remove the import module.

¥Valid

import fs from "fs-custom";
import type path from "node:path";

¥Related links