Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack 5 dynamic require syntax causes un-necessary files to be traced/included for lambdas #21297

Closed
ijjk opened this issue Jan 18, 2021 · 1 comment · Fixed by #22697
Closed
Milestone

Comments

@ijjk
Copy link
Member

ijjk commented Jan 18, 2021

What version of Next.js are you using?

10.0.5 (canary as well)

What version of Node.js are you using?

v12.20.0

What browser are you using?

all

What operating system are you using?

macOS, Linux, Windows

How are you deploying your application?

Vercel

Describe the Bug

When dynamic imports are used dynamic chunks are created for the server build and dynamic required.

In webpack 4 the syntax used to require these dynamic chunks was able to be statically evaluated:

/******/ 		if(installedChunks[chunkId] !== 0) {
/******/ 			var chunk = require("../" + ({}[chunkId]||chunkId) + "." + {"0":"432e819ee916cf1fe474","1":"c1993a54b4b250bfacf9","2":"cfea81a5890bf53bdfc6","3":"944259e4b104c150480c"}[chunkId] + ".js");

In webpack 5 the syntax used is no longer able to statically evaluated which requires dependency tracing solutions to guess which files are needed in the relative directory used usually causing entire directories that aren't needed to be marked as needed e.g. the entire .next/serverless/pages directory is being included from the below require.

	// "1" is the signal for "already loaded"
/******/ 			if(!installedChunks[chunkId]) {
/******/ 				if(true) { // all chunks have JS
/******/ 					installChunk(require("../../" + __webpack_require__.u(chunkId)));
/******/ 				} else installedChunks[chunkId] = 1;
/******/ 			}

Expected Behavior

To be able to trace and include only the needed files in webpack 5 the same way we were able to in webpack 4

To Reproduce

Use webpack 5 with a dependency tracing solution like node-file-trace to detect needed files

@Timer Timer added this to the 10.x.x milestone Jan 18, 2021
@kodiakhq kodiakhq bot closed this as completed in #22697 Mar 3, 2021
@Timer Timer modified the milestones: 10.x.x, iteration 17 Mar 3, 2021
kodiakhq bot pushed a commit that referenced this issue Mar 3, 2021
This updates to output server chunks to a nested folder to prevent bundling the entire folder when tracing. This also fixes the webpack 5 tests not actually using webpack 5 since #22583 since the webpack 5 enabling check didn't account for the test environment variable used to enable webpack 5. This also clears up some deprecation warnings from webpack 5 in the mini-css-extract-plugin.

Fixes: #21297
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants