Disable findSourceMap when --enable-source-maps is not passed (#21478)

### 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?
This commit is contained in:
Jarred Sumner
2025-07-30 00:09:42 -07:00
parent 6ca1f7cd48
commit 3e456d4bb0

View File

@@ -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;