oxc-project/oxc · error · OxcDiagnostic
Relative imports before absolute imports are prohibited
Error message
Relative imports before absolute imports are prohibited
What it means
Fires from import/first with the 'absolute-first' option enabled when a relative import appears before an absolute (package/bare specifier) import. The diagnostic labels the relative import's span; enabling absolute-first is what activates this check.
Source
Thrown at crates/oxc_linter/src/rules/import/first.rs:20
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{
context::LintContext,
rule::{DefaultRuleConfig, Rule},
};
fn first_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Import statements must come first")
.with_help("Move import statement to the top of the file")
.with_label(span)
}
fn absolute_first_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Relative imports before absolute imports are prohibited")
.with_help("Move absolute import above relative import")
.with_label(span)
}
#[derive(Debug, Default, Clone, Deserialize, Serialize)]
pub struct First(AbsoluteFirst);
#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
enum AbsoluteFirst {
/// Forces absolute imports to be listed before relative imports.
///
/// Examples of **incorrect** code for this rule with `"absolute-first"`:
/// ```js
/// import { x } from './foo';
/// import { y } from 'bar'
/// ```
///View on GitHub (pinned to e1e7af627c)
Solutions
- Reorder imports so absolute/package imports come before relative ones
- Disable the absolute-first option if the ordering is intentional
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/import/first.rs:20 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/6963e149ebd1b81e.
Report an issue: GitHub.