{"record":{"id":"c09c45efc8734d36","repo":"oxc-project/oxc","slug":"prefer-using-the-node-protocol-when-importing-n","errorCode":null,"errorMessage":"Prefer using the `node:` protocol when importing Node.js built-in modules.","messagePattern":"Prefer using the `node:` protocol when importing Node\\.js built-in modules\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_node_protocol.rs","lineNumber":13,"sourceCode":"use nodejs_built_in_modules::is_nodejs_builtin_module;\nuse oxc_ast::{\n    AstKind,\n    ast::{Expression, TSModuleReference},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn prefer_node_protocol_diagnostic(span: Span, module_name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"Prefer using the `node:` protocol when importing Node.js built-in modules.\",\n    )\n    .with_help(format!(\"Prefer `node:{module_name}` over `{module_name}`.\"))\n    .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferNodeProtocol;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prefer using the `node:` protocol when importing Node.js built-in modules.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Node.js built-in modules should be imported using the `node:` protocol to avoid ambiguity with local modules.\n    ///","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_node_protocol.rs#L1-L31","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_node_protocol.rs:13 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}