swc-project/swc · error
failed to create a temp file
Error message
failed to create a temp file
What it means
`exec_with_node_test_runner` writes the generated mocha test file with `OpenOptions::new().create(true).truncate(true).write(true).open(&path)`. The `expect("failed to create a temp file")` panics when opening `{tmpdir}/{hash}.test.js` for writing fails — almost always permission or disk-space issues on the temp directory just created, since the parent directory already exists at this point.
Source
Thrown at crates/swc_ecma_transforms_testing/src/lib.rs:663
println!("Trying cache as `SWC_CACHE_TEST` is `1`");
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()View on GitHub (pinned to 5176682b65)
Solutions
- Verify you can create files inside `$CARGO_TARGET_DIR/swc-es-exec-testing/` manually; fix ACLs/ownership if not.
- Clear stale contents of the scratch dir (`rm -rf $CARGO_TARGET_DIR/swc-es-exec-testing`) to remove collided/locked files; it is a pure cache/scratch area.
- Free disk space if ENOSPC, and disable execution tests (`EXEC=0`) in environments that cannot write there.
Defensive patterns
Strategy: validation
Validate before calling
fn can_create_files_under(p: &std::path::Path) -> bool {
let probe = p.join(".file-probe");
std::fs::write(&probe, b"").is_ok() && {
let _ = std::fs::remove_file(&probe);
true
}
} Prevention
- Run a writable-probe check on $CARGO_TARGET_DIR/swc-es-exec-testing in CI before cargo test.
- Clear the scratch dir when stale/locked files from crashed runs remain.
- On Windows, exclude the target dir from antivirus scanning to avoid creation blocks.
When it happens
Trigger: Execution tests where the temp dir exists but is not writable (ACLs, SELinux denials), the filesystem filled up between dir creation and file creation, or antivirus/mandatory-locking environments blocking file creation on Windows.
Common situations: Hardened CI images with restrictive ACLs on the cargo target dir; disk-full agents; Windows environments where another process holds a lock on a same-named leftover file.
Related errors
- failed to create parent directory for temp directory
- failed to create a temp directory
- failed to read file
- failed to write to temp file
- failed to run mocha
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/7a2e761888eb4989.
Report an issue: GitHub.