Skip to content

Commit 76da32e

Browse files
fix(WellKnownErrorsPlugin): avoid compilation warnings array with empty items (#57768)
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: #57073 --------- Co-authored-by: Jimmy Lai <laijimmy0@gmail.com>
1 parent 2e82ca8 commit 76da32e

File tree

1 file changed

+1
-1
lines changed
  • packages/next/src/build/webpack/plugins/wellknown-errors-plugin

1 file changed

+1
-1
lines changed

packages/next/src/build/webpack/plugins/wellknown-errors-plugin/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class WellKnownErrorsPlugin {
1414
warn.name === 'ModuleDependencyWarning' &&
1515
warn.module.context?.includes('node_modules')
1616
) {
17-
delete compilation.warnings[i]
17+
compilation.warnings.splice(i, 1)
1818
}
1919
})
2020
)

0 commit comments

Comments
 (0)