oxc-project/oxc · error · OxcDiagnostic
Do not construct dirname.
Error message
Do not construct dirname.
What it means
Diagnostic from the unicorn/prefer-import-meta-properties lint rule. It fires when code manually derives a directory path from `import.meta.url` (typically via `fileURLToPath()` plus `dirname()` from `node:path`) instead of using the built-in `import.meta.dirname` property available in modern Node.js. The flagged input is the expression computing the directory of the current module. It is a lint suggestion, not a runtime error.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/prefer_import_meta_properties.rs:48
impl ProblemKind {
fn message(self) -> &'static str {
match self {
Self::Dirname => "Do not construct dirname.",
Self::Filename => "Do not construct filename using `fileURLToPath()`.",
}
}
fn property(self) -> &'static str {
match self {
Self::Dirname => "dirname",
Self::Filename => "filename",
}
}
}
fn prefer_import_meta_diagnostic(span: Span, kind: ProblemKind) -> OxcDiagnostic {
OxcDiagnostic::warn(kind.message())
.with_help(format!("Replace this expression with `import.meta.{}`.", kind.property()))
.with_label(span)
}
fn report_problem(ctx: &LintContext<'_>, span: Span, kind: ProblemKind) {
ctx.diagnostic_with_fix(prefer_import_meta_diagnostic(span, kind), |fixer| {
fixer.replace(span, format!("import.meta.{}", kind.property()))
});
}
#[derive(Debug, Default, Clone)]
pub struct PreferImportMetaProperties;
declare_oxc_lint!(
/// ### What it does
///
/// Prefer `import.meta.{dirname,filename}` over legacy
/// techniques for getting file paths.View on GitHub (pinned to e1e7af627c)
Solutions
- Replace the `dirname(fileURLToPath(import.meta.url))` expression with `import.meta.dirname`
- Drop the now-unused `node:path` and `node:url` imports
- Apply the rule's auto-fix
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/prefer_import_meta_properties.rs:48 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/ed1a15267dc7a399.
Report an issue: GitHub.