From 3e456d4bb0ca04f901f7fdb359a8d9bfb65c4f0b Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 30 Jul 2025 00:09:42 -0700 Subject: [PATCH] Disable `findSourceMap` when `--enable-source-maps` is not passed (#21478) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What does this PR do? Fixes the error printed: ```js ❯ bun --bun dev $ next dev --turbopack ▲ Next.js 15.4.5 (Turbopack) - Local: http://localhost:3000 - Network: http://192.168.1.250:3000 ✓ Starting... ✓ Ready in 637ms ○ Compiling / ... ✓ Compiled / in 1280ms /private/tmp/empty/my-app/.next/server/chunks/ssr/[root-of-the-server]__012ba519._.js: Invalid source map. Only conformant source maps can be used to filter stack frames. Cause: TypeError: payload is not an Object. (evaluating '"sections" in payload') /private/tmp/empty/my-app/.next/server/chunks/ssr/[root-of-the-server]__93bf7db5._.js: Invalid source map. Only conformant source maps can be used to filter stack frames. Cause: TypeError: payload is not an Object. (evaluating '"sections" in payload') GET / 200 in 1416ms ^C^[[A ``` ### How did you verify your code works? --- src/sourcemap/JSSourceMap.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/sourcemap/JSSourceMap.zig b/src/sourcemap/JSSourceMap.zig index 21c5c10b90..3222d56ffd 100644 --- a/src/sourcemap/JSSourceMap.zig +++ b/src/sourcemap/JSSourceMap.zig @@ -6,10 +6,22 @@ sourcemap: *bun.sourcemap.ParsedSourceMap, sources: []bun.String = &.{}, names: []bun.String = &.{}, +/// TODO: when we implement --enable-source-map CLI flag, set this to true. +pub var @"--enable-source-maps" = false; + fn findSourceMap( globalObject: *JSGlobalObject, callFrame: *CallFrame, ) bun.JSError!JSValue { + // Node.js doesn't enable source maps by default. + // In Bun, we do use them for almost all files since we transpile almost all files + // If we enable this by default, we don't have a `payload` object since we don't internally create one. + // This causes Next.js to emit errors like the below on start: + // .next/server/chunks/ssr/[root-of-the-server]__012ba519._.js: Invalid source map. Only conformant source maps can be used to filter stack frames. Cause: TypeError: payload is not an Object. (evaluating '"sections" in payload') + if (!@"--enable-source-maps") { + return .js_undefined; + } + const source_url_value = callFrame.argument(0); if (!source_url_value.isString()) { return .js_undefined;