{"record":{"id":"036f2bb05aef5988","repo":"DioxusLabs/dioxus","slug":"esbuild-failed-stderr","errorCode":null,"errorMessage":"esbuild failed: {stderr}","messagePattern":"esbuild failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/opt/js.rs","lineNumber":85,"sourceCode":"    }\n\n    if lexer::js_is_module(js_options, source) {\n        cmd.arg(\"--bundle\");\n        cmd.arg(\"--format=esm\");\n        // Don't try to resolve URL-based imports at build time — let the\n        // browser fetch them at runtime. Without these externals, esbuild\n        // errors out on patterns like `import x from \"https://cdn/lib.js\"`.\n        cmd.arg(\"--external:https://*\");\n        cmd.arg(\"--external:http://*\");\n    }\n\n    tracing::debug!(\"Running esbuild: {:?}\", cmd);\n\n    let output = cmd.output().context(\"Failed to run esbuild\")?;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"esbuild failed: {stderr}\");\n    }\n\n    Ok(())\n}\n\npub(crate) fn hash_js(\n    _js_options: &JsAssetOptions,\n    source: &Path,\n    hasher: &mut impl std::hash::Hasher,\n) -> anyhow::Result<()> {\n    hash_file_contents(source, hasher)\n}\n\npub use lexer::*;\nmod lexer {\n    //! Detect whether a JavaScript source file uses ES module syntax.\n    //!\n    //! This is a token-level scanner inspired by Guy Bedford's `es-module-lexer`","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/393d190a801ccb441d41923e232289b4f8a5c669/packages/cli/src/opt/js.rs#L67-L103","documentation":"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.)","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Reproduce esbuild's verdict on the asset before dx build\nesbuild --bundle assets/app.js --outfile=/dev/null --external:https://* --external:http://*","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["cli","esbuild","javascript","build"],"backgroundTag":null,"analyzedSha":"393d190a801ccb441d41923e232289b4f8a5c669","analyzedAt":"2026-08-16T11:27:45.815Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}