Skip to content

Latest commit

 

History

History
67 lines (45 loc) · 1.45 KB

prefer-node-protocol.md

File metadata and controls

67 lines (45 loc) · 1.45 KB

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

This rule is part of the recommended config.

🔧 This rule is auto-fixable.

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.

And don't forget to upvote this issue if you agree.

Fail

import dgram from 'dgram';
export {strict as default} from 'assert';
import fs from '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';

Options

Type: object

checkRequire

Type: boolean
Default: false

Currently, require(…) with the node: protocol is only available on Node.js 16. If you don't care about old versions, you can set this to true.

We'll remove this option and check require(…) by default once this feature get backported to v12.

// eslint unicorn/prefer-node-protocol: ["error", {"checkRequire": true}]
const fs = require('fs'); // Fails