From 2b6210e430af4a8476924c584fc5e426542eaba8 Mon Sep 17 00:00:00 2001 From: "jj@jjsweb.site" Date: Wed, 6 Oct 2021 10:36:01 -0500 Subject: [PATCH 1/2] Ensure conditional resolve alias does not affect server --- packages/next/build/webpack-config.ts | 17 +++++++++++------ test/integration/production/test/index.test.js | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 655b4c8da2f12..d1294f9ae4bb7 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -504,12 +504,17 @@ 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 - isWebpack5 - ? false - : clientResolveRewritesNoop, + + ...(!isServer + ? { + [clientResolveRewrites]: hasRewrites + ? clientResolveRewrites + : // With webpack 5 an alias can be pointed to false to noop + isWebpack5 + ? false + : clientResolveRewritesNoop, + } + : {}), }, ...(isWebpack5 && !isServer ? { diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js index 6474f4d9225aa..3ebfccd7aa625 100644 --- a/test/integration/production/test/index.test.js +++ b/test/integration/production/test/index.test.js @@ -133,6 +133,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/], }, From 6aeccbf3900019e55d8f221a6390434947b99840 Mon Sep 17 00:00:00 2001 From: "jj@jjsweb.site" Date: Wed, 6 Oct 2021 10:42:55 -0500 Subject: [PATCH 2/2] update tests --- test/integration/production/test/index.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js index 3ebfccd7aa625..e631bdc99bafe 100644 --- a/test/integration/production/test/index.test.js +++ b/test/integration/production/test/index.test.js @@ -107,6 +107,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/], }, @@ -120,6 +123,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/], }, @@ -145,6 +149,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/], },