diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index f6483bf435c09fe..e512d9f0e94cddc 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -491,10 +491,15 @@ export default async function getBaseWebpackConfig( [DOT_NEXT_ALIAS]: distDir, ...getOptimizedAliases(isServer), ...getReactProfilingInProduction(), - [clientResolveRewrites]: hasRewrites - ? clientResolveRewrites - : // With webpack 5 an alias can be pointed to false to noop - false, + + ...(!isServer + ? { + [clientResolveRewrites]: hasRewrites + ? clientResolveRewrites + : // With webpack 5 an alias can be pointed to false to noop + false, + } + : {}), }, ...(!isServer ? { diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js index c534701ff7bd792..7a99d2eebb1eddf 100644 --- a/test/integration/production/test/index.test.js +++ b/test/integration/production/test/index.test.js @@ -93,6 +93,9 @@ describe('Production Usage', () => { /node_modules\/react\/index\.js/, /node_modules\/react\/package\.json/, /node_modules\/react\/cjs\/react\.production\.min\.js/, + /next\/link\.js/, + /next\/dist\/client\/link\.js/, + /next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/, ], notTests: [/node_modules\/react\/cjs\/react\.development\.js/], }, @@ -106,6 +109,7 @@ describe('Production Usage', () => { /node_modules\/react\/cjs\/react\.production\.min\.js/, /next\/link\.js/, /next\/dist\/client\/link\.js/, + /next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/, ], notTests: [/node_modules\/react\/cjs\/react\.development\.js/], }, @@ -119,6 +123,7 @@ describe('Production Usage', () => { /node_modules\/react\/cjs\/react\.production\.min\.js/, /next\/router\.js/, /next\/dist\/client\/router\.js/, + /next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/, ], notTests: [/node_modules\/react\/cjs\/react\.development\.js/], }, @@ -130,6 +135,9 @@ describe('Production Usage', () => { /node_modules\/react\/index\.js/, /node_modules\/react\/package\.json/, /node_modules\/react\/cjs\/react\.production\.min\.js/, + /next\/link\.js/, + /next\/dist\/client\/link\.js/, + /next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/, ], notTests: [/next\/dist\/server\/next\.js/, /next\/dist\/bin/], },