diff --git a/crates/turbopack-json/src/lib.rs b/crates/turbopack-json/src/lib.rs index efd996c690b30..6a668c3530195 100644 --- a/crates/turbopack-json/src/lib.rs +++ b/crates/turbopack-json/src/lib.rs @@ -122,9 +122,10 @@ impl EcmascriptChunkItem for JsonChunkItem { let data = content.parse_json().await?; match &*data { FileJsonContent::Content(data) => { - let js_str_content = serde_json::to_string(data)?; + let js_str_content = serde_json::to_string(&data.to_string())?; let inner_code = format!("__turbopack_export_value__(JSON.parse({js_str_content}));"); + Ok(EcmascriptChunkItemContent { inner_code: inner_code.into(), ..Default::default() @@ -139,6 +140,7 @@ impl EcmascriptChunkItem for JsonChunkItem { } else { write!(message, "{}", e)?; } + Err(Error::msg(message)) } FileJsonContent::NotFound => { diff --git a/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js b/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js index f548a0fc47800..2d3a5d0aff1ca 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js +++ b/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js @@ -13,7 +13,7 @@ console.log(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$ })()), "[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/package.json (json)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { -__turbopack_export_value__(JSON.parse({"name":"json-snapshot"})); +__turbopack_export_value__(JSON.parse("{\"name\":\"json-snapshot\"}")); })()), "[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json)": (() => {{ @@ -1071,4 +1071,4 @@ globalThis.TURBOPACK = { })(); -//# sourceMappingURL=crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js.map \ No newline at end of file +//# sourceMappingURL=crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js.map