From 76da32e43fc5aafc9787f53a772458e828febbcd Mon Sep 17 00:00:00 2001 From: Luis Henrique Mulinari Date: Mon, 13 Nov 2023 08:48:44 -0300 Subject: [PATCH] fix(WellKnownErrorsPlugin): avoid compilation warnings array with empty items (#57768) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, when a webpack compilation warning is processed by `WellKnownErrorsPlugin` and it's indeed a well know error that should be bypassed, the warning item is simply deleted from the array, which will produce an array with empty items: Example: ```js { client: { loading: false, totalModulesCount: 2172, errors: null, warnings: [ <1 empty item> ] }, server: { loading: false, totalModulesCount: 2119, errors: null, warnings: [ <1 empty item> ] }, edgeServer: { loading: false, totalModulesCount: 58, errors: null, warnings: null }, trigger: undefined, amp: {} } ``` This array with empty items generates a side effect on the [build output](https://github.com/vercel/next.js/blob/3553c6516d7a9aba98876f9660af0ee7c94dc2a3/packages/next/src/build/output/store.ts#L124), since the `warning` array has empty items: ``` ➤ npm run dev > next dev ▲ Next.js 14.0.1-canary.3 - Local: http://localhost:3000 - Environments: .env.development ✓ Ready in 2.6s ✓ Compiled /middleware in 109ms (58 modules) ○ Compiling /(dashboard)/page ... ⚠ ⚠ ``` ![CleanShot 2023-10-30 at 13 20 42@2x](https://github.com/vercel/next.js/assets/33168/fd25bc72-61d6-4446-83cb-87768d5135dd) This PR solves this issue by removing the `warning` item using the `Array.prototype.splice`, which removes the item instead of making the array position empty. Related PR: https://github.com/vercel/next.js/pull/57073 --------- Co-authored-by: Jimmy Lai --- .../src/build/webpack/plugins/wellknown-errors-plugin/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/build/webpack/plugins/wellknown-errors-plugin/index.ts b/packages/next/src/build/webpack/plugins/wellknown-errors-plugin/index.ts index ffe51e0e99e7d..55bc1c3609974 100644 --- a/packages/next/src/build/webpack/plugins/wellknown-errors-plugin/index.ts +++ b/packages/next/src/build/webpack/plugins/wellknown-errors-plugin/index.ts @@ -14,7 +14,7 @@ export class WellKnownErrorsPlugin { warn.name === 'ModuleDependencyWarning' && warn.module.context?.includes('node_modules') ) { - delete compilation.warnings[i] + compilation.warnings.splice(i, 1) } }) )