From d2c1888a257b4a5390a11bf1850eb10434ce967f Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Sat, 6 Nov 2021 01:19:25 +0100 Subject: [PATCH] update serverless plugin to use webpack 5 apis (#31058) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/next/build/webpack/plugins/serverless-plugin.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/next/build/webpack/plugins/serverless-plugin.ts b/packages/next/build/webpack/plugins/serverless-plugin.ts index 055c294e1b6271b..f2eb42c539794c8 100644 --- a/packages/next/build/webpack/plugins/serverless-plugin.ts +++ b/packages/next/build/webpack/plugins/serverless-plugin.ts @@ -14,7 +14,8 @@ export class ServerlessPlugin { hook.tap('ServerlessPlugin', (chunks) => { for (const chunk of chunks) { // If chunk is not an entry point skip them - if (!chunk.hasEntryModule()) { + // @ts-ignore TODO: Remove ignore when webpack 5 is stable + if (compilation.chunkGraph.getNumberOfEntryModules(chunk) === 0) { continue } @@ -26,7 +27,11 @@ export class ServerlessPlugin { dynamicChunk )) { // Add module back into the entry chunk - chunk.addModule(module) + // @ts-ignore TODO: Remove ignore when webpack 5 is stable + if (!compilation.chunkGraph.isModuleInChunk(module, chunk)) { + // @ts-ignore TODO: Remove ignore when webpack 5 is stable + compilation.chunkGraph.connectChunkAndModule(chunk, module) + } } } }