DioxusLabs/dioxus · error
failed to create output dir
Error message
failed to create output dir
What it means
The wasm-split CLI's `split` subcommand deletes any existing directory at `out_dir` (ignoring errors) and then recreates it with `std::fs::create_dir_all(...).expect("failed to create output dir")`. If the OS refuses to create the directory, the process panics with exit code 101 before any wasm work happens. This is an environment failure (permissions, disk, path collision), not a problem with the wasm binaries being split.
Source
Thrown at packages/wasm-split/wasm-split-cli/src/main.rs:46
#[derive(Parser)]
struct SplitArgs {
/// The wasm module emitted by rustc
original: PathBuf,
/// The wasm module emitted by wasm-bindgen
bindgened: PathBuf,
/// The output *directory* to write the split wasm files to
out_dir: PathBuf,
}
fn split(args: SplitArgs) {
let original = std::fs::read(&args.original).expect("failed to read input file");
let bindgened = std::fs::read(&args.bindgened).expect("failed to read input file");
_ = std::fs::remove_dir_all(&args.out_dir);
std::fs::create_dir_all(&args.out_dir).expect("failed to create output dir");
tracing::info!("Building split module");
let module = wasm_split_cli::Splitter::new(&original, &bindgened).unwrap();
let mut chunks = module.emit().unwrap();
// Write out the main module
tracing::info!(
"Writing main module to {}",
args.out_dir.join("main.wasm").display()
);
std::fs::write(args.out_dir.join("main.wasm"), &chunks.main.bytes).unwrap();
// Write the js module
std::fs::write(
args.out_dir.join("__wasm_split.js"),
emit_js(&chunks.chunks, &chunks.modules),View on GitHub (pinned to 393d190a80)
Solutions
- Check whether a file (not a directory) occupies the out_dir path (`ls -la <out_dir>`) and remove or rename it
- Verify the parent directory is writable (`chmod u+w` on the parent, or choose another location)
- Pass an absolute out_dir path so the location does not depend on the invoker's cwd
- Free disk space or raise the quota, then re-run the split command
Example fix
# before: dist exists as a file, split panics with "failed to create output dir" wasm-split-cli split app.wasm bg.wasm dist # after: clear the collision and use an absolute path rm -f dist && wasm-split-cli split app.wasm bg.wasm "$(pwd)/dist"
Defensive patterns
Strategy: validation
Validate before calling
OUT_DIR="$(pwd)/dist"
if [ -e "$OUT_DIR" ] && [ ! -d "$OUT_DIR" ]; then echo "out_dir exists and is not a directory"; exit 1; fi
mkdir -p "$OUT_DIR" 2>/dev/null || { echo "cannot create out_dir"; exit 1; }
[ -w "$OUT_DIR" ] || { echo "out_dir is not writable"; exit 1; }
wasm-split-cli split app.wasm bg.wasm "$OUT_DIR" Try / catch
if ! wasm-split-cli split app.wasm bg.wasm "$OUT_DIR"; then echo "split failed (exit $?) - check the panic message for the OS error" >&2; exit 1; fi
Prevention
- Run the writable-directory pre-flight check above in CI before invoking wasm-split-cli
- Always pass an absolute out_dir so cwd differences cannot redirect it
- Never point out_dir at a path that may hold a build artifact file
- Treat exit code 101 with this message as an environment failure - fix the path or permissions rather than re-running unchanged
When it happens
Trigger: Running `wasm-split-cli split <original> <bindgened> <out_dir>` where a regular file already occupies the out_dir path (remove_dir_all silently fails on files, so create_dir_all hits EEXIST/ENOTDIR); the parent directory is read-only or lacks write permission for the current user; the path is on a full disk, an unwritable mount, or exceeds filesystem path-length limits.
Common situations: CI containers running as non-root with a restricted workspace; passing `dist` as out_dir when `dist` already exists as a build artifact file; a relative out_dir resolved from an unexpected working directory when the binary is invoked by a script; Docker disk quota exhausted.
Related errors
- failed to write chunk
- Failed to create args directory for rustc wrapper
- failed to expand ifunc table
- Could not find export
- failed to read input file
AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16).
Data as JSON: /api/errors/c4db7f75715de3b9.
Report an issue: GitHub.