diff --git a/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts b/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts index 107d5971c7d09..7995032ac9726 100644 --- a/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts +++ b/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts @@ -24,10 +24,16 @@ export function formatRSCErrorMessage( formattedVerboseMessage = '\n\nMaybe one of these should be marked as a client entry with "use client":\n' } else if (NEXT_RSC_ERR_SERVER_IMPORT.test(message)) { - formattedMessage = message.replace( - NEXT_RSC_ERR_SERVER_IMPORT, - `\n\nYou're importing a component that imports $1. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.\n\n` - ) + const matches = message.match(NEXT_RSC_ERR_SERVER_IMPORT) + if (matches && matches[1] === 'react-dom/server') { + // If importing "react-dom/server", we should show a different error. + formattedMessage = `\n\nYou're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.` + } else { + formattedMessage = message.replace( + NEXT_RSC_ERR_SERVER_IMPORT, + `\n\nYou're importing a component that imports $1. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.\n\n` + ) + } formattedVerboseMessage = '\n\nMaybe one of these should be marked as a client entry "use client":\n' } else if (NEXT_RSC_ERR_CLIENT_IMPORT.test(message)) {