Skip to content

Commit

Permalink
Ensure conditional resolve alias does not affect server (#29673)
Browse files Browse the repository at this point in the history
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: #25538 (comment)
  • Loading branch information
ijjk authored Oct 6, 2021
1 parent aa8a885 commit a20b0d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? {
Expand Down
8 changes: 8 additions & 0 deletions test/integration/production/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/],
},
Expand All @@ -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/],
},
Expand All @@ -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/],
},
Expand All @@ -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/],
},
Expand Down

0 comments on commit a20b0d5

Please sign in to comment.