Skip to content

Latest commit

Β 

History

History
62 lines (44 loc) Β· 1.32 KB

File metadata and controls

62 lines (44 loc) Β· 1.32 KB

prefer-node-protocol

πŸ“ Prefer using the node: protocol when importing Node.js builtin modules.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

When getting 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.

Examples

// ❌
import dgram from 'dgram';

// βœ…
import dgram from 'node:dgram';
// ❌
export {strict as default} from 'assert';

// βœ…
export {strict as default} from 'node:assert';
// ❌
import fs from 'fs/promises';

// βœ…
import fs from 'node:fs/promises';
// ❌
const fs = require('fs/promises');

// βœ…
const fs = require('node:fs/promises');
// ❌
const fs = process.getBuiltinModule('fs/promises');

// βœ…
const fs = process.getBuiltinModule('node:fs/promises');
// ❌
type Fs = import('fs');

// βœ…
type Fs = import('node:fs');