oxc-project/oxc · error · OxcDiagnostic
Do not construct filename using `fileURLToPath()`.
Error message
Do not construct filename using `fileURLToPath()`.
What it means
Diagnostic from the unicorn/prefer-import-meta-properties lint rule. It fires when code converts `import.meta.url` to a file path with `fileURLToPath()` to obtain the current module's file name; `import.meta.filename` provides this directly in modern Node.js. The flagged input is the `fileURLToPath(import.meta.url)` expression. 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 `fileURLToPath(import.meta.url)` with `import.meta.filename` when only the file path is needed
- Use `import.meta.dirname`/`path.join` if a specific path composition is intended
- Drop the unused `node:url` import and 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/d27e534229c505bf.
Report an issue: GitHub.