diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index d54d3c9f8c2b..26f541b0c195 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -1277,6 +1277,16 @@ export default async function getBaseWebpackConfig( ].filter(Boolean), }, plugins: [ + // Produce source maps for middlewares + new webpack.SourceMapDevToolPlugin({ + filename: '[file].map', + include: [ + // Middlewares are the only ones who have `server/pages/[name]` as their filename + /^server\/pages\//, + // All middleware chunks + /^server\/middleware-chunks\//, + ], + }), hasReactRefresh && new ReactRefreshWebpackPlugin(webpack), // Makes sure `Buffer` and `process` are polyfilled in client and flight bundles (same behavior as webpack 4) targetWeb &&