swc-project/swc · error
failed to create a temp directory
Error message
failed to create a temp directory
What it means
After ensuring the scratch root exists, `exec_with_node_test_runner` creates a temp directory inside it with `tempdir_in(&root)`. The `expect("failed to create a temp directory")` panics when tempfile cannot create that directory: permission denied on the parent, disk/inode exhaustion, or platform temp-creation limits (e.g. name collisions or EMFILE on some systems).
Source
Thrown at crates/swc_ecma_transforms_testing/src/lib.rs:653
fn exec_with_node_test_runner(src: &str) -> Result<(), ()> {
let root = CARGO_TARGET_DIR.join("swc-es-exec-testing");
create_dir_all(&root).expect("failed to create parent directory for temp directory");
let hash = calc_hash(src);
let success_cache = root.join(format!("{hash}.success"));
if env::var("SWC_CACHE_TEST").unwrap_or_default() == "1" {
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);View on GitHub (pinned to 5176682b65)
Solutions
- Fix permissions/ownership of `$CARGO_TARGET_DIR/swc-es-exec-testing` so the test user can create directories.
- Check free space and inodes (`df -h`, `df -i`) and clean the build disk.
- Reduce test parallelism if fd/inode exhaustion is implicated, or raise ulimits in the CI job.
- As a workaround for constrained envs, disable execution tests with `EXEC=0`.
Defensive patterns
Strategy: validation
Validate before calling
fn can_create_dirs_under(p: &std::path::Path) -> bool {
let probe = p.join(".dir-probe");
std::fs::create_dir(&probe).is_ok() && {
let _ = std::fs::remove_dir(&probe);
true
}
} Prevention
- Verify directory-creation rights on the target dir in CI setup scripts.
- Monitor disk and inode usage on build agents (df -h / df -i).
- Avoid mixing users when running cargo to prevent ownership mismatches under target/.
When it happens
Trigger: Execution tests running with a read-only or root-owned `$CARGO_TARGET_DIR/swc-es-exec-testing`, out-of-space or out-of-inode filesystems, or heavy parallel test execution hitting file-descriptor limits.
Common situations: Same environments as the directory-creation failure: locked-down CI sandboxes, mixed-ownership target dirs after sudo runs, full build disks.
Related errors
- failed to create parent directory for temp directory
- failed to create a temp file
- failed to read file
- failed to run mocha
- Fallback bindings does not support filesystem access.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/c100a721dec58c58.
Report an issue: GitHub.