denoland/deno · error
bundling failed
Error message
bundling failed
What it means
Watch-mode bundling: esbuild returned a BuildResponse containing errors. handle_esbuild_errors_and_warnings prints them (with file:line:col) first, then the run bails with this generic message to force a non-zero exit (cli/tools/bundle/mod.rs:366-375) instead of entering the watch loop on a broken graph.
Source
Thrown at cli/tools/bundle/mod.rs:374
)
.await?;
}
let bundler = bundle_init(flags.clone(), &bundle_flags, None).await?;
let init_cwd = bundler.cwd.clone();
let start = std::time::Instant::now();
let response = bundler.build().await?;
let end = std::time::Instant::now();
let duration = end.duration_since(start);
if bundle_flags.watch {
if !response.errors.is_empty() || !response.warnings.is_empty() {
handle_esbuild_errors_and_warnings(
&response,
&init_cwd,
&bundler.plugin_handler.take_deferred_resolve_errors(),
);
if !response.errors.is_empty() {
deno_core::anyhow::bail!("bundling failed");
}
}
return bundle_watch(
flags,
bundler,
bundle_flags.minify,
bundle_flags.platform,
bundle_flags.output_dir.as_ref().map(Path::new),
)
.await;
}
handle_esbuild_errors_and_warnings(
&response,
&init_cwd,
&bundler.plugin_handler.take_deferred_resolve_errors(),
);
View on GitHub (pinned to 89f33cbef2)
Solutions
- Read the esbuild diagnostics printed immediately above - they carry the exact file, line, and column of the first error
- Fix imports first: use explicit extensions (./util.ts not ./util), and run deno install if an npm:/jsr: dependency is missing
- Verify the project type-checks/compiles once outside watch mode (deno check <entry>, deno bundle <entry>) before restarting watch
- If errors come from half-written files on save, configure the editor to write atomically or debounce saves
Example fix
// before: extensionless import trips esbuild resolution under watch
import { helper } from './util';
// after
import { helper } from './util.ts'; Defensive patterns
Strategy: try-catch
Validate before calling
# Gate the watch session on a clean one-shot bundle first
deno bundle --outdir /tmp/gate src/main.ts || { echo 'fix bundle errors before watching'; exit 1; }
deno bundle --watch --outdir dist src/main.ts Try / catch
# Wrapper: surface the real esbuild diagnostics when watch aborts
log=$(mktemp)
deno bundle --watch --outdir dist src/main.ts 2>&1 | tee "$log" || {
echo '--- watch exited; first error: ---'
grep -m1 -A3 'ERROR' "$log"
} Prevention
- Use explicit .ts/.js extensions on relative imports
- Run deno install before watch sessions on fresh checkouts
- Configure editors to write files atomically/debounced so half-saved buffers don't break the graph
When it happens
Trigger: deno bundle --watch with a syntax error, an unresolvable import, or a plugin onResolve failure in the entry graph; a file edit that temporarily breaks the graph (half-saved file); missing npm/jsr dependency not yet installed.
Common situations: Editor autosave writing mid-edit buffers during watch; importing a file with a missing ./extension (Deno requires explicit extensions); deleting/renaming a module that the entry imports while watching.
Related errors
- esbuild exited before the rebuild completed
- could not get fetch esbuild binary; download it manually and
- failed to locate output for HTML entry '{}'; {js_entry_name}
- esbuild produced no JavaScript output
- The bench function must have a name
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/a20ec3e535f5278d.
Report an issue: GitHub.