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.
This rule is fixable.
import dgram from 'dgram';
export {strict as default} from 'assert';
import fs from 'fs/promises';
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';
Type: object
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