Skip to content

Commit

Permalink
fix(next): disable turbopack serverExternalPackages warnings (#9147)
Browse files Browse the repository at this point in the history
### What?
Disables these annoying warnings when running `pnpm dev --turbo`
<img width="656" alt="image"
src="https://github.com/user-attachments/assets/7d0a2990-b5fd-4f5d-a025-665e8e3a7880">
vercel/next.js#68805

### How?
Patches `console.warn` in `withPayload.js`

Can be disabled with `PAYLOAD_PATCH_TURBOPACK_WARNINGS=false` env
variable
  • Loading branch information
r1tsuu authored Nov 12, 2024
1 parent e0309a1 commit 64967e4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/next/src/withPayload.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ export const withPayload = (nextConfig = {}) => {
env.NEXT_PUBLIC_ENABLE_ROUTER_CACHE_REFRESH = 'true'
}

if (process.env.PAYLOAD_PATCH_TURBOPACK_WARNINGS !== 'false') {
const consoleWarn = console.warn

console.warn = (...args) => {
// Force to disable serverExternalPackages warnings: https://github.com/vercel/next.js/issues/68805
if (
typeof args[1] === 'string' &&
args[1].includes(
'Packages that should be external need to be installed in the project directory, so they can be resolved from the output files.\nTry to install it into the project directory by running',
)
) {
return
}

consoleWarn(...args)
}
}

const poweredByHeader = {
key: 'X-Powered-By',
value: 'Next.js, Payload',
Expand Down

0 comments on commit 64967e4

Please sign in to comment.