swc-project/swc · error
failed to execute: {} {}
Error message
failed to execute:
{}
{} What it means
swc_ecma_testing's execution helper runs minified/transpiled JS by spawning a node process (`node --input-type=commonjs -e <code>` plus extra args) and checking the exit status. When node exits nonzero, it bails with 'failed to execute' followed by the child's captured stdout and stderr. The error is test-harness level: the produced code itself crashed or failed assertions at runtime under node.
Source
Thrown at crates/swc_ecma_testing/src/lib.rs:90
let mut c = Command::new("node");
if opts.module {
c.arg("--input-type=module");
} else {
c.arg("--input-type=commonjs");
}
c.arg("-e").arg(js_code);
for arg in opts.args {
c.arg(arg);
}
let output = c.output().context("failed to execute output of minifier")?;
if !output.status.success() {
bail!(
"failed to execute:\n{}\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
)
}
String::from_utf8(output.stdout).context("output is not utf8")
}
/// Writes through a temporary path so parallel test threads never observe a
/// partially-written cache file.
fn write_cache_file(cache_path: &Path, bytes: &[u8]) -> Result<()> {
let cache_dir = cache_path
.parent()
.context("cache path should have a parent directory")?;
let write_id = CACHE_WRITE_ID.fetch_add(1, Ordering::Relaxed);
let tmp_path = cache_dir.join(format!(
".{}.{}.tmp",View on GitHub (pinned to 5176682b65)
Solutions
- Read the embedded stderr in the message: it is the actual node error (stack trace, assertion failure) and points at the failing code
- Reproduce by extracting the stdout/stderr code block into a file and running node on it directly to debug the runtime failure
- If the failure is a minifier-caused behavior change, minimize the case and report/fix it in swc rather than skipping the test
- Ensure node is on PATH with a supported version and any required runtime deps are installed where the test runs
Example fix
// before: assertion inside executed code fails silently
let output = executor.run("assert.strictEqual(add(1,2),4)".into()).await?; // add(1,2)==3
// after: correct the expectation (or the minified output) so the code exits 0
let output = executor.run("assert.strictEqual(add(1,2),3)".into()).await?; Defensive patterns
Strategy: try-catch
Validate before calling
// Skip execution when the environment cannot run node
import { spawnSync } from 'node:child_process';
const nodeOk = spawnSync('node', ['--version'], { stdio: 'ignore' }).status === 0; Try / catch
let out = executor.run(js_code).await;
if out.is_err() {
// error body embeds child stdout+stderr; log it verbatim for diagnosis
eprintln!("node execution failed: {out:?}");
} Prevention
- Ensure `node` is on PATH and versions match the test matrix before running swc_ecma_testing suites
- Install runtime dependencies of test fixtures in the working directory
- Treat a failure here as a behavioral bug signal: minimize and upstream it instead of ignoring
When it happens
Trigger: Calling the test executor (e.g. via default_executor/ RuntimeExecutor::new(NodeExecutor::default().await)) on minified output whose runtime behavior throws, references missing globals/modules, or fails an assertion; also when extra opts.args pass node flags node rejects.
Common situations: Minifier/debug output regression: the minified bundle behaves differently from the original (dropped this-binding, inlined constants, broken helpers); test environment missing node on PATH or an incompatible node version; runtime dependencies not installed in the test cwd.
Related errors
- Infinite loop detected (current pass = {}) {}
- failed to parse `global_defs.{k}` of minifier options: {err:
- Value of `global_defs.{k}` must be a string literal:
- failed to parse `pure_funcs` of minifier options: {err:?}
- `{raw}` is not a valid ecmascript version
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/2cbc64ba46415df8.
Report an issue: GitHub.