Improve bundling error message formatting (#55794)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55794

Format the error messages coming from bundling to mainting the formatting and make these easier to read.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D94611951

fbshipit-source-id: cbb8b2d1ff517b5487d4b799b1e2e3476629f84c
This commit is contained in:
Nick Lefever
2026-03-01 17:49:19 -08:00
committed by meta-codesync[bot]
parent d6042d2161
commit b2efda00a8
+13 -3
View File
@@ -52,9 +52,19 @@ export async function createBundle(options: BundleOptions): Promise<void> {
);
if (lastBundleError || lastBundleResult?.ok !== true) {
throw new Error(
`Failed to request bundle from Metro: ${lastBundleError?.message ?? (await lastBundleResult?.text()) ?? ''}`,
);
let errorMessage =
lastBundleError?.message ?? (await lastBundleResult?.text()) ?? '';
try {
const parsed = JSON.parse(errorMessage);
if (typeof parsed.message === 'string') {
errorMessage = parsed.message;
}
} catch {
// Not JSON — use the raw text as-is.
}
throw new Error(`Failed to request bundle from Metro:\n${errorMessage}`);
}
await fs.promises.writeFile(