Skip to content

Commit 475d448

Browse files
committed
mimic next response
1 parent 8823100 commit 475d448

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/nextjs/rollup.npm.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default [
1717
// prevent this internal nextjs code from ending up in our built package (this doesn't happen automatically because
1818
// the name doesn't match an SDK dependency)
1919
packageSpecificConfig: {
20-
external: ['next/router', 'next/constants', 'next/headers', 'next/server', 'stacktrace-parser'],
20+
external: ['next/router', 'next/constants', 'next/headers', 'stacktrace-parser'],
2121

2222
// Next.js and our users are more happy when our client code has the "use client" directive
2323
plugins: [

packages/nextjs/src/common/wrapMiddlewareWithSentry.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
winterCGRequestToRequestData,
1414
withIsolationScope,
1515
} from '@sentry/core';
16-
import { NextResponse } from 'next/server';
1716
import type { EdgeRouteHandler } from '../edge/types';
1817
import { flushSafelyWithTimeout } from './utils/responseEnd';
1918

@@ -41,7 +40,15 @@ export function wrapMiddlewareWithSentry<H extends EdgeRouteHandler>(
4140
const isTunnelRequest = url.pathname.startsWith(tunnelRoute);
4241

4342
if (isTunnelRequest) {
44-
return NextResponse.next() as ReturnType<H>;
43+
// Create a simple response that mimics NextResponse.next() so we don't need to import internals here
44+
// which breaks next 13 apps
45+
// https://github.com/vercel/next.js/blob/c12c9c1f78ad384270902f0890dc4cd341408105/packages/next/src/server/web/spec-extension/response.ts#L146
46+
return new Response(null, {
47+
status: 200,
48+
headers: {
49+
'x-middleware-next': '1',
50+
},
51+
}) as ReturnType<H>;
4552
}
4653
}
4754
}

0 commit comments

Comments
 (0)