diff --git a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts index 66c3224d3b2c..c7fcaa45cc78 100644 --- a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts @@ -147,6 +147,31 @@ export class ClientReferenceManifestPlugin { traverseModules(compilation, (mod) => collectClientRequest(mod)) compilation.chunkGroups.forEach((chunkGroup) => { + function getAppPathRequiredChunks() { + return chunkGroup.chunks + .map((requiredChunk: webpack.Chunk) => { + if (SYSTEM_ENTRYPOINTS.has(requiredChunk.name)) { + return null + } + + // Get the actual chunk file names from the chunk file list. + // It's possible that the chunk is generated via `import()`, in + // that case the chunk file name will be '[name].[contenthash]' + // instead of '[name]-[chunkhash]'. + return [...requiredChunk.files].map((file) => { + // It's possible that a chunk also emits CSS files, that will + // be handled separatedly. + if (!file.endsWith('.js')) return null + if (file.endsWith('.hot-update.js')) return null + + return requiredChunk.id + ':' + file + }) + }) + .flat() + .filter(nonNullable) + } + const requiredChunks = getAppPathRequiredChunks() + const recordModule = ( id: ModuleId, mod: webpack.NormalModule, @@ -247,31 +272,6 @@ export class ClientReferenceManifestPlugin { ), ] - function getAppPathRequiredChunks() { - return chunkGroup.chunks - .map((requiredChunk: webpack.Chunk) => { - if (SYSTEM_ENTRYPOINTS.has(requiredChunk.name)) { - return null - } - - // Get the actual chunk file names from the chunk file list. - // It's possible that the chunk is generated via `import()`, in - // that case the chunk file name will be '[name].[contenthash]' - // instead of '[name]-[chunkhash]'. - return [...requiredChunk.files].map((file) => { - // It's possible that a chunk also emits CSS files, that will - // be handled separatedly. - if (!file.endsWith('.js')) return null - if (file.endsWith('.hot-update.js')) return null - - return requiredChunk.id + ':' + file - }) - }) - .flat() - .filter(nonNullable) - } - const requiredChunks = getAppPathRequiredChunks() - // The client compiler will always use the CJS Next.js build, so here we // also add the mapping for the ESM build (Edge runtime) to consume. const esmResource = /[\\/]next[\\/]dist[\\/]/.test(resource)