swc-project/swc · error
failed to write to temp file
Error message
failed to write to temp file
What it means
Immediately after creating the temp file, `exec_with_node_test_runner` writes the transformed source with `write!(tmp, "{src}")`. The `expect("failed to write to temp file")` panics when the write itself fails: the filesystem filled up (ENOSPC), a quota was hit mid-write, or the file handle became invalid.
Source
Thrown at crates/swc_ecma_transforms_testing/src/lib.rs:664
if success_cache.exists() {
println!("Cache: success");
return Ok(());
}
}
let tmp_dir = tempdir_in(&root).expect("failed to create a temp directory");
create_dir_all(&tmp_dir).unwrap();
let path = tmp_dir.path().join(format!("{hash}.test.js"));
let mut tmp = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&path)
.expect("failed to create a temp file");
write!(tmp, "{src}").expect("failed to write to temp file");
tmp.flush().unwrap();
let test_runner_path = find_executable("mocha").expect("failed to find `mocha` from path");
let mut base_cmd = if cfg!(target_os = "windows") {
let mut c = Command::new("cmd");
c.arg("/C").arg(&test_runner_path);
c
} else {
Command::new(&test_runner_path)
};
let output = base_cmd
.arg(format!("{}", path.display()))
.arg("--color")
.current_dir(root)
.output()
.expect("failed to run mocha");View on GitHub (pinned to 5176682b65)
Solutions
- Check disk space (`df -h $CARGO_TARGET_DIR`) and free space or raise the quota.
- Clean the scratch area and cargo caches (`cargo clean`, remove `$CARGO_TARGET_DIR/swc-es-exec-testing`) to reclaim room.
- On overlayfs/container limits, raise the container's writable-layer size or bind-mount a larger volume at the target dir.
- Skip execution tests with `EXEC=0` on space-constrained runners.
Defensive patterns
Strategy: validation
Validate before calling
fn disk_has_space(p: &std::path::Path) -> bool {
// Simplest portable check: write a small file and read it back.
let probe = p.join(".space-probe");
let ok = std::fs::write(&probe, vec![0u8; 1024]).is_ok();
let _ = std::fs::remove_file(&probe);
ok
} Prevention
- Keep build disks below capacity; large bundles make the generated .test.js files big.
- Periodically clean $CARGO_TARGET_DIR/swc-es-exec-testing (it is scratch/cache).
- Set EXEC=0 on quota-limited runners where writes may fail mid-file.
When it happens
Trigger: Execution tests running on a full disk or quota-limited volume where the (potentially large, since it embeds the whole transformed bundle) test file cannot be fully written; flaky mounts (network filesystems, overlayfs under memory pressure).
Common situations: Build agents whose disks fill during large test batches; container overlay filesystems hitting the size limit; per-user quotas exceeded in shared CI.
Related errors
- failed to create a temp file
- failed to read file
- failed to execute transfomred code
- CARGO_MANIFEST_DIR
- test_inlined_transform does not support paths outside of the
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/a6bb878bd05914d8.
Report an issue: GitHub.