swc-project/swc · error
Invalid JSON
Error message
Invalid JSON
What it means
Node binding panic in MinifyTarget::to_file: the JS side passed MinifyTarget::Json whose payload is not valid JSON for FxHashMap<String,String>, so serde_json::from_str failed and .expect aborted the process instead of returning a napi error.
Source
Thrown at bindings/binding_core_node/src/minify.rs:46
input: Option<MinifyTarget>,
options: String,
extras: JsMinifyExtras,
}
enum MinifyTarget {
/// Code to minify.
Single(String),
/// `FxHashMap<String, String>`
Json(String),
}
impl MinifyTarget {
fn to_file(&self, cm: Lrc<SourceMap>) -> Lrc<SourceFile> {
match self {
MinifyTarget::Single(code) => cm.new_source_file(FileName::Anon.into(), code.clone()),
MinifyTarget::Json(json) => {
let codes: FxHashMap<String, String> =
serde_json::from_str(json).expect("Invalid JSON");
assert_eq!(
codes.len(),
1,
"swc.minify does not support concatting multiple files yet"
);
let (filename, code) = codes.iter().next().unwrap();
cm.new_source_file(FileName::Real(filename.clone().into()).into(), code.clone())
}
}
}
}
#[napi]
impl Task for MinifyTask {
type JsValue = TransformOutput;
type Output = TransformOutput;View on GitHub (pinned to 5176682b65)
Solutions
- Pass a JSON object mapping file names to code strings
- Replace expect with proper error propagation so malformed JSON returns a catchable napi::Error
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at bindings/binding_core_node/src/minify.rs:46 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/e8724d8ebcd3ea9f.
Report an issue: GitHub.