swc-project/swc · error
failed to read program file
Error message
failed to read program file
What it means
Fired in parse_file_sync: `c.cm.load_file(Path::new(path))` failed to read the source file from disk and the code calls `.expect(...)`, panicking with this message. The input at fault is the `path` argument — a nonexistent, unreadable, or otherwise unloadable file path. Because expect() is used, callers receive a panic rather than a structured napi error.
Source
Thrown at bindings/binding_core_node/src/parse.rs:237
Ok((p, fm))
})
})
.convert_err()?;
Ok(serialize_program(program, &fm)?)
}
#[napi]
pub fn parse_file_sync(path: String, opts: Buffer) -> napi::Result<String> {
crate::util::init_default_trace_subscriber();
let c = get_fresh_compiler();
let options: ParseOptions = get_deserialized(&opts)?;
let (program, fm) = {
try_with(c.cm.clone(), false, ErrorFormat::Normal, |handler| {
let fm =
c.cm.load_file(Path::new(path.as_str()))
.expect("failed to read program file");
let local_comments = SwcComments::default();
let comments = if options.comments {
Some(&local_comments as &dyn Comments)
} else {
None
};
let mut p = c.parse_js(
fm.clone(),
handler,
options.target,
options.syntax,
options.is_module,
comments,
)?;
p.visit_mut_with(&mut resolver(
Mark::new(),View on GitHub (pinned to 5176682b65)
Solutions
- Verify the path exists and the process has read permission before calling parseFileSync
- Propagate load_file errors via convert_err/try_with so JS receives a proper error object
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at bindings/binding_core_node/src/parse.rs:237 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/38fa804ae2ffd519.
Report an issue: GitHub.