swc-project/swc · error
failed to load file
Error message
failed to load file
What it means
Node binding panic in transform_file_sync: cm.load_file for the requested source path failed inside the try_with closure, and .expect('failed to load file') turned the I/O failure into a process aborting panic rather than a napi error.
Source
Thrown at bindings/binding_core_node/src/transform.rs:270
let c = compiler_for_program_input(&program_input, get_compiler());
try_with(
c.cm.clone(),
!options.config.error.filename.into_bool(),
error_format,
|handler| c.run(|| process_program_input(&c, handler, program_input, &options)),
)
.convert_err()
} else {
let c = get_fresh_compiler();
try_with(
c.cm.clone(),
!options.config.error.filename.into_bool(),
error_format,
|handler| {
c.run(|| {
let fm = c.cm.load_file(Path::new(&s)).expect("failed to load file");
c.process_js_file(fm, handler, &options)
})
},
)
.convert_err()
}
}
View on GitHub (pinned to 5176682b65)
Solutions
- Check the file path and read permissions before calling transformFileSync
- Return the load_file error through the handler so JS gets a catchable error
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at bindings/binding_core_node/src/transform.rs:270 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/9ee00d6cb913cb83.
Report an issue: GitHub.