DioxusLabs/dioxus · error · anyhow::Error
esbuild failed: {stderr}
Error message
esbuild failed: {stderr} What it means
For JS/TS assets, dx shells out to the esbuild binary as a subprocess. If the process runs but exits non-zero, its captured stderr is re-raised as 'esbuild failed: {stderr}'. (A failure to spawn the binary would produce 'Failed to run esbuild' instead, so this error means esbuild itself rejected the input.)
Source
Thrown at packages/cli/src/opt/js.rs:85
}
if lexer::js_is_module(js_options, source) {
cmd.arg("--bundle");
cmd.arg("--format=esm");
// Don't try to resolve URL-based imports at build time — let the
// browser fetch them at runtime. Without these externals, esbuild
// errors out on patterns like `import x from "https://cdn/lib.js"`.
cmd.arg("--external:https://*");
cmd.arg("--external:http://*");
}
tracing::debug!("Running esbuild: {:?}", cmd);
let output = cmd.output().context("Failed to run esbuild")?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
anyhow::bail!("esbuild failed: {stderr}");
}
Ok(())
}
pub(crate) fn hash_js(
_js_options: &JsAssetOptions,
source: &Path,
hasher: &mut impl std::hash::Hasher,
) -> anyhow::Result<()> {
hash_file_contents(source, hasher)
}
pub use lexer::*;
mod lexer {
//! Detect whether a JavaScript source file uses ES module syntax.
//!
//! This is a token-level scanner inspired by Guy Bedford's `es-module-lexer`View on GitHub (pinned to 393d190a80)
Solutions
- Read the esbuild stderr embedded in the message — it names the file, line, and problem
- Reproduce outside dx by running esbuild on the same file with the same flags to iterate quickly
- Fix the import/parse error, or mark the problematic dependency external
- If you suspect a version mismatch, install esbuild 0.27.3 on PATH and run it manually to confirm behavior
Defensive patterns
Strategy: validation
Validate before calling
# Reproduce esbuild's verdict on the asset before dx build esbuild --bundle assets/app.js --outfile=/dev/null --external:https://* --external:http://*
Prevention
- Keep JS/TS assets compilable by esbuild 0.27.3
- Cover remote CDN imports with the external flags or avoid them
- Validate assets with a local esbuild run in CI to catch errors with full stderr
When it happens
Trigger: esbuild rejecting a JS/TS asset: unresolved relative imports, syntax it cannot parse, or remote http(s) imports when the external flags do not cover the pattern; the subprocess's stderr is passed through verbatim.
Common situations: Importing CDN URLs with schemes not covered by --external:https://* / --external:http://*; TS syntax unsupported by the pinned esbuild 0.27.3; broken relative paths after moving asset files.
Related errors
- esbuild not found on PATH and downloads are disabled
- No esbuild binary available for this platform
- esbuild binary not found in archive (expected one of {}). Fo
- Failed to run linker
- Failed to execute rustc command
AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16).
Data as JSON: /api/errors/036f2bb05aef5988.
Report an issue: GitHub.