oxc-project/oxc · error · OxcDiagnostic
Do not import modules using an absolute path
Error message
Do not import modules using an absolute path
What it means
Fires from import/no-absolute-path when a module specifier is an absolute filesystem path (e.g. '/usr/lib/foo' or 'C:\\...'). The run visitor detects absolute paths in import declarations and require() calls and labels the span, suggesting a relative path or module alias instead.
Source
Thrown at crates/oxc_linter/src/rules/import/no_absolute_path.rs:22
use serde_json::Value;
use oxc_ast::{
AstKind,
ast::{Argument, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use serde::Deserialize;
use crate::{
AstNode,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
};
fn no_absolute_path_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Do not import modules using an absolute path")
.with_help("Replace the absolute path with a relative path or a module alias.")
.with_label(span)
}
// <https://github.com/import-js/eslint-plugin-import/blob/v2.31.0/docs/rules/no-absolute-path.md>
#[derive(Debug, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoAbsolutePath {
/// If set to `true`, dependency paths for ES module import statements will be resolved:
///
/// ```js
/// import foo from '/foo'; // reported
/// ```
esmodule: bool,
/// If set to `true`, dependency paths for CommonJS-style require calls will be resolved:
///
/// ```js
/// var foo = require('/foo'); // reportedView on GitHub (pinned to e1e7af627c)
Solutions
- Replace the absolute path with a relative path
- Configure and use a module alias (bundler/tsconfig paths) for stable imports
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/import/no_absolute_path.rs:22 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/850f1198197d1196.
Report an issue: GitHub.