noNodejsModules
诊断类别:lint/correctness/noNodejsModules
¥Diagnostic Category: lint/correctness/noNodejsModules
自从:v1.5.0
来源:
¥Since: v1.5.0
Sources:
-
与以下相同:
import/no-nodejs-modules
¥Same as:
import/no-nodejs-modules
禁止使用 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
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.
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
¥Related links