Skip to content

Commit 5c184f4

Browse files
authored
fix(nextjs): Avoid wrapping middleware files when in standalone mode (#18172)
This PR attempts to fix #18001 by not wrapping the middleware files if Next.js 16 is the current version and is in standalone output mode which is the problematic scenario. Investigation: - Next.js renames `proxy` to `middleware` under the hood. - By wrapping the middleware a `proxy.js` entry is produced in `middleware.js.nft.json` which wouldn't be there otherwise, meaning if we don't wrap it then that entry doesn't get produced. So it seems like `@vercel/nft` is somehow adding the `proxy` file as a dependency of itself which fails to copy to the output directory because it was already copied and renamed to `proxy.js` or at least that is what I'm guessing is happening.
1 parent 679a02c commit 5c184f4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ export function constructWebpackConfigFunction({
276276
});
277277

278278
// Wrap middleware
279-
if (userSentryOptions.autoInstrumentMiddleware ?? true) {
279+
const canWrapStandaloneMiddleware = userNextConfig.output !== 'standalone' || !major || major < 16;
280+
if ((userSentryOptions.autoInstrumentMiddleware ?? true) && canWrapStandaloneMiddleware) {
280281
newConfig.module.rules.unshift({
281282
test: isMiddlewareResource,
282283
use: [

0 commit comments

Comments
 (0)