oxc-project/oxc · warning · OxcDiagnostic

async is not allowed

Error message

async is not allowed

What it means

Oxlint restriction rule `oxc/no_async_await` unconditionally disallows `async` functions and `await` expressions. It exists for projects that must ship synchronous-only or Promise-chain-only code (restrictive transpilation targets, embedded/legacy JS engines, or a strict house style). The diagnostic points at the `async` keyword span and the only fix is removing the syntax or disabling the rule.

Source

Thrown at crates/oxc_linter/src/rules/oxc/no_async_await.rs:9

use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

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

fn no_async_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("async is not allowed")
        .with_help("Remove the `async` keyword")
        .with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallows the use of `async`/`await`.
    ///
    /// This rule should generally not be used in modern JavaScript/TypeScript
    /// codebases without good reason.
    ///
    /// ### Why is this bad?
    ///
    /// This rule is useful for environments that don't support `async`/`await` syntax,

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Rewrite the code with plain promise chains (`.then`/`.catch`) instead of async/await
  2. If the constraint does not apply, turn the rule off in `.oxlintrc.json`: `"oxc/no_async_await": "off"`
  3. Keep the rule but scope it with `overrides` to only the directories that genuinely must stay sync

Example fix

// before
async function load(url) {
  const res = await fetch(url);
  return res.json();
}

// after
function load(url) {
  return fetch(url).then((res) => res.json());
}
Defensive patterns

Strategy: fallback

Prevention

When it happens

Trigger: Any `async function` declaration, `async` arrow, async method, or `await` expression in a linted file when the `oxc` plugin's `no_async_await` rule is enabled (e.g. `"oxc/no_async_await": "error"` in `.oxlintrc.json`).

Common situations: Enabling the oxc restriction category wholesale; projects targeting ES5-only transpilers or runtimes without async support; porting an internal 'no async' coding standard to oxlint and hitting existing modern code.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/3cd2f7ab69605a88. Report an issue: GitHub.