DioxusLabs/dioxus · error
failed to write chunk
Error message
failed to write chunk
What it means
Each split chunk is written as `chunk_<idx>_<module_name>.wasm` in out_dir, and a failed `std::fs::write` panics with "failed to write chunk". Besides ordinary IO problems (disk full, permissions revoked), the filename embeds the chunk's module_name, so a name containing characters invalid in filenames on the target OS - or a combined name exceeding the filesystem's 255-byte component limit - makes exactly this write fail while earlier writes succeeded.
Source
Thrown at packages/wasm-split/wasm-split-cli/src/main.rs:81
args.out_dir.join("__wasm_split.js"),
emit_js(&chunks.chunks, &chunks.modules),
)
.expect("failed to write js module");
for (idx, chunk) in chunks.chunks.iter().enumerate() {
tracing::info!(
"Writing chunk {} to {}",
idx,
args.out_dir
.join(format!("chunk_{}_{}.wasm", idx, chunk.module_name))
.display()
);
std::fs::write(
args.out_dir
.join(format!("chunk_{}_{}.wasm", idx, chunk.module_name)),
&chunk.bytes,
)
.expect("failed to write chunk");
}
for (idx, module) in chunks.modules.iter_mut().enumerate() {
tracing::info!(
"Writing module {} to {}",
idx,
args.out_dir
.join(format!(
"module_{}_{}.wasm",
idx,
module.component_name.as_ref().unwrap()
))
.display()
);
std::fs::write(
args.out_dir.join(format!(
"module_{}_{}.wasm",
idx,View on GitHub (pinned to 393d190a80)
Solutions
- Read the tracing line printed just above the panic - it shows the exact target path; check that filename for invalid characters or excessive length
- Free disk space or restore write permissions on out_dir, then re-run
- Shorten the out_dir path so the combined generated filename fits within 255 bytes
- Rename the offending Rust module (or patch/report wasm-split's name sanitization) if the module_name is not filename-safe on the target OS
Example fix
# before: deep out_dir + long module name exceeds NAME_MAX on this filesystem wasm-split-cli split app.wasm bg.wasm /very/long/build/prefix/dist # after: shorter output root (and/or rename the deep Rust module) wasm-split-cli split app.wasm bg.wasm dist
Defensive patterns
Strategy: validation
Validate before calling
# before invoking, confirm the target filesystem accepts the generated names
name_max=$(stat -f -c %l dist 2>/dev/null || stat -f -l dist 2>/dev/null || echo 255)
find dist -name 'chunk_*' -printf '%f\n' 2>/dev/null | awk -v m="$name_max" 'length($0) >= m { print "filename too long: " $0; exit 1 }' Try / catch
if ! wasm-split-cli split app.wasm bg.wasm dist; then echo "chunk write failed (exit $?) - check the logged chunk path for invalid characters/length" >&2; exit 1; fi
Prevention
- Enable the CLI's debug logging (it logs each target path before writing) and eyeball generated chunk names once per build
- Prefer short out_dir roots so generated names stay under NAME_MAX
- Build on the same OS you deploy from, or verify module names are filename-safe on Windows/macOS
- Keep free disk headroom so late writes do not fail after early ones succeed
When it happens
Trigger: A chunk module_name containing `/`, `\`, or characters like `:` that are invalid on Windows; an out_dir path plus generated name exceeding NAME_MAX; ENOSPC or revoked permissions after the earlier main.wasm and JS glue writes consumed the remaining space or the lock changed.
Common situations: Cross-platform builds where a name is legal on Linux but invalid on Windows/macOS; deeply nested Rust module paths producing very long generated filenames; Docker inode exhaustion mid-build.
Related errors
- failed to create output dir
- failed to expand ifunc table
- Could not find export
- failed to read input file
- failed to write js module
AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16).
Data as JSON: /api/errors/569f97be6ed3ef82.
Report an issue: GitHub.