Skip to content

Commit

Permalink
fix(WellKnownErrorsPlugin): avoid compilation warnings array with emp…
Browse files Browse the repository at this point in the history
…ty 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 <[email protected]>
  • Loading branch information
luismulinari and feedthejim authored Nov 13, 2023
1 parent 2e82ca8 commit 76da32e
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
)
Expand Down

0 comments on commit 76da32e

Please sign in to comment.