swc-project/swc · error
failed to execute transfomred code
Error message
failed to execute transfomred code
What it means
In the babel_like harness, execution tests that compare stdout first run the TRANSFORMED code through node via `stdout_of(&code)` (which delegates to `exec_node_js`). The `expect("failed to execute transfomred code")` (typo intentional, it is in the source) fires when running the transformed output fails to produce stdout: node cannot be spawned or the transformed code crashes/errors when executed.
Source
Thrown at crates/swc_ecma_transforms_testing/src/babel_like.rs:202
Color::Green.paint("Code"),
code_without_helper
);
if let Some(output_path) = output_path {
// Fixture test
if !self.allow_error && handler.has_errors() {
return Err(());
}
NormalizedOutput::from(code)
.compare_to_file(output_path)
.unwrap();
} else if compare_stdout {
// Execution test, but compare stdout
let actual_stdout: String =
stdout_of(&code).expect("failed to execute transfomred code");
let expected_stdout =
stdout_of(&fm.src).expect("failed to execute transfomred code");
testing::assert_eq!(actual_stdout, expected_stdout);
} else {
// Execution test
exec_with_node_test_runner(&format!("// {}\n{code}", self.input.display()))
.expect("failed to execute transfomred code");
}
Ok(())
});
if self.allow_error {
match err {
Ok(_) => {}
Err(err) => {View on GitHub (pinned to 5176682b65)
Solutions
- Run the failing fixture manually: the harness prints the transformed code; save it and run `node file.js` to see the real error.
- Install node and ensure it is on PATH (`node --version` from the same shell that runs cargo).
- If node is too old for the emitted syntax (e.g. top-level await, class fields), upgrade node.
- Temporarily skip execution tests with `EXEC=0 cargo test` while diagnosing, then re-enable.
Defensive patterns
Strategy: validation
Validate before calling
// Skip execution tests when node is unavailable.
fn node_available() -> bool {
std::process::Command::new("node")
.arg("--version")
.output()
.map(|o| o.status.success())
.unwrap_or(false)
} Prevention
- Ensure `node --version` works in the exact shell/CI step that runs cargo test.
- Keep transformed output runnable on the installed node version (mind newer syntax features).
- Use EXEC=0 to exclude execution tests in node-less environments.
When it happens
Trigger: A `compare_stdout`-style fixture where the transformed code throws at runtime (bad transform output, reference error, syntax the generated code uses but node rejects), or the `node` executable is missing from PATH in the test environment.
Common situations: Running execution tests (`EXEC != 0`) in CI images without node installed; a transform regression that emits broken code; transformed output using syntax newer than the installed node version.
Related errors
- CARGO_MANIFEST_DIR
- test_inlined_transform does not support paths outside of the
- failed to get current directory
- failed to read file
- failed to create parent directory for temp directory
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/d7127f799fd346af.
Report an issue: GitHub.