From 7d5cc4005afbcbcfa8b6c17badd6d58a9d185615 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 6 Oct 2021 12:16:01 -0500 Subject: [PATCH] Ensure conditional resolve alias does not affect server (#29673) This ensures we don't add the no-op resolve alias when rewrites aren't used for the server resolving since it is still needed while tracing server files. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [x] Errors have helpful link attached, see `contributing.md` Fixes: https://github.com/vercel/next.js/pull/25538#issuecomment-936101951 --- packages/next/build/webpack-config.ts | 13 +++++++++---- test/integration/production/test/index.test.js | 8 ++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) 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/], },