Skip to content

Commit 2c1b288

Browse files
author
Luca Forstner
authored
fix(nextjs): Fix sourcemaps resolving for local dev when basePath is set (#9457)
1 parent 460bea1 commit 2c1b288

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/nextjs/src/common/devErrorSymbolicationEventProcessor.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Event, EventHint } from '@sentry/types';
2+
import { GLOBAL_OBJ } from '@sentry/utils';
23
import type { StackFrame } from 'stacktrace-parser';
34
import * as stackTraceParser from 'stacktrace-parser';
45

@@ -8,6 +9,10 @@ type OriginalStackFrameResponse = {
89
sourcePackage?: string;
910
};
1011

12+
const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
13+
__sentryBasePath?: string;
14+
};
15+
1116
async function resolveStackFrame(
1217
frame: StackFrame,
1318
error: Error,
@@ -26,13 +31,20 @@ async function resolveStackFrame(
2631
params.append(key, (frame[key as keyof typeof frame] ?? '').toString());
2732
});
2833

34+
let basePath = globalWithInjectedValues.__sentryBasePath ?? '';
35+
36+
// Prefix the basepath with a slash if it doesn't have one
37+
if (basePath !== '' && !basePath.match(/^\//)) {
38+
basePath = `/${basePath}`;
39+
}
40+
2941
const controller = new AbortController();
3042
const timer = setTimeout(() => controller.abort(), 3000);
3143
const res = await fetch(
3244
`${
3345
// eslint-disable-next-line no-restricted-globals
3446
typeof window === 'undefined' ? 'http://localhost:3000' : '' // TODO: handle the case where users define a different port
35-
}/__nextjs_original-stack-frame?${params.toString()}`,
47+
}${basePath}/__nextjs_original-stack-frame?${params.toString()}`,
3648
{
3749
signal: controller.signal,
3850
},

packages/nextjs/src/config/webpack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ function addValueInjectionLoader(
955955
SENTRY_RELEASE: buildContext.dev
956956
? undefined
957957
: { id: sentryWebpackPluginOptions.release ?? getSentryRelease(buildContext.buildId) },
958+
__sentryBasePath: userNextConfig.basePath,
958959
};
959960

960961
const serverValues = {

0 commit comments

Comments
 (0)