noNodejsModules
¥Summary
-
规则生效日期:
v1.5.0¥Rule available since:
v1.5.0 -
诊断类别:
lint/correctness/noNodejsModules¥Diagnostic Category:
lint/correctness/noNodejsModules -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
¥Same as
import/no-nodejs-modules
-
¥How to configure
{ "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
Biome v2.1 中文网 - 粤ICP备13048890号