Skip to content

unicorn/prefer-node-protocol Restriction

🛠️ An auto-fix is available for this rule.

What it does

Prefer using the node:protocol when importing Node.js builtin modules

Why is this bad?

Node.js builtin modules should be imported using the node: protocol to avoid ambiguity with local modules.

Examples

Examples of incorrect code for this rule:

javascript
import fs from "fs";

Examples of correct code for this rule:

javascript
import fs from "node:fs";

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/prefer-node-protocol": "error"
  }
}
bash
oxlint --deny unicorn/prefer-node-protocol

References

Released under the MIT License.