Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 1.22 KB

File metadata and controls

65 lines (45 loc) · 1.22 KB

Prefer using the node: protocol when importing Node.js builtin modules (node-import/prefer-node-protocol)

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

When importing builtin modules, it's better to use the node: protocol as it makes it perfectly clear that the package is a Node.js builtin module.

Note that Node.js support for this feature began in:

v16.0.0, v14.18.0 (require())

v14.13.1, v12.20.0 (import)

As such, the minimal Node version for this plugin is v14.18.0.

Fail

import dgram from "dgram";
export { strict as default } from "assert";
import fs from "fs/promises";
const fs = require("fs/promises");

Pass

import dgram from "node:dgram";
export { strict as default } from "node:assert";
import fs from "node:fs/promises";
const fs = require("fs");
import _ from "lodash";
import fs from "./fs.js";
const fs = require("node:fs/promises");