oxc-project/oxc · error · OxcDiagnostic

Do not use "use strict" directive.

Error message

Do not use "use strict" directive.

What it means

Diagnostic from the unicorn/prefer-module lint rule. It fires when a "use strict" directive appears in a file that is (or should be) an ES module: ES modules are always parsed in strict mode, so the directive is redundant. The flagged input is the directive prologue statement. It is a lint suggestion, not a runtime error.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/prefer_module.rs:15

use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{
    AstNode,
    context::{ContextHost, LintContext},
    rule::Rule,
};

const COMMON_JS_GLOBALS: [&str; 5] = ["exports", "require", "module", "__filename", "__dirname"];

fn use_strict_directive_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(r#"Do not use "use strict" directive."#)
        .with_help("ES modules are always strict mode, so this directive is redundant.")
        .with_label(span)
}

fn global_return_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(r#""return" should be used inside a function."#).with_label(span)
}

fn common_js_global_diagnostic(span: Span, name: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(r#"Do not use "{name}"."#))
        .with_help("Prefer ES modules over CommonJS globals.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct PreferModule;

declare_oxc_lint!(

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Delete the `"use strict";` directive
  2. Ensure the file is treated as a module (ESM `import`/`export` or `.mjs`) so strictness applies automatically
  3. Apply the rule's auto-fix
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/prefer_module.rs:15 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/2e706049b33a6bb7. Report an issue: GitHub.