oxc-project/oxc · error · OxcDiagnostic
Prefer using the `node:` protocol when importing Node.js bui
Error message
Prefer using the `node:` protocol when importing Node.js built-in modules.
What it means
Diagnostic from the unicorn/prefer-node-protocol lint rule. It fires when an import (or `require`/`import()` of a TS module reference) loads a Node.js built-in module by bare name — the message names the module (e.g. `fs`, `path`) — instead of using the `node:` prefixed specifier. The prefixed form is unambiguous, forward-compatible, and blocks userland shadowing. It is a lint suggestion, not a runtime error.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/prefer_node_protocol.rs:13
use nodejs_built_in_modules::is_nodejs_builtin_module;
use oxc_ast::{
AstKind,
ast::{Expression, TSModuleReference},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{AstNode, context::LintContext, rule::Rule};
fn prefer_node_protocol_diagnostic(span: Span, module_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(
"Prefer using the `node:` protocol when importing Node.js built-in modules.",
)
.with_help(format!("Prefer `node:{module_name}` over `{module_name}`."))
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct PreferNodeProtocol;
declare_oxc_lint!(
/// ### What it does
///
/// Prefer using the `node:` protocol when importing Node.js built-in modules.
///
/// ### Why is this bad?
///
/// Node.js built-in modules should be imported using the `node:` protocol to avoid ambiguity with local modules.
///View on GitHub (pinned to e1e7af627c)
Solutions
- Change `import fs from 'fs'` to `import fs from 'node:fs'`
- Update `require('path')` to `require('node:path')` and dynamic `import()` specifiers likewise
- Apply the rule's auto-fix, which rewrites the specifier
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/prefer_node_protocol.rs:13 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/c09c45efc8734d36.
Report an issue: GitHub.