From 7f5e456523cb1b14e84cdf8edb3c9f7026cd29d6 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Fri, 5 Nov 2021 23:29:31 +0100 Subject: [PATCH] update serverless plugin to use webpack 5 apis --- 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) + } } } }