From 64967e4ca6968bfa28274d44b39a5acb4dee3188 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Tue, 12 Nov 2024 22:20:11 +0200 Subject: [PATCH] fix(next): disable turbopack serverExternalPackages warnings (#9147) ### What? Disables these annoying warnings when running `pnpm dev --turbo` image https://github.com/vercel/next.js/issues/68805 ### How? Patches `console.warn` in `withPayload.js` Can be disabled with `PAYLOAD_PATCH_TURBOPACK_WARNINGS=false` env variable --- packages/next/src/withPayload.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/next/src/withPayload.js b/packages/next/src/withPayload.js index 9a921ab94..9967f70dc 100644 --- a/packages/next/src/withPayload.js +++ b/packages/next/src/withPayload.js @@ -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',