diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index 9f03654422687..02df819079c96 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -2,7 +2,6 @@ import React from 'react' import ReactRefreshWebpackPlugin from 'next/dist/compiled/@next/react-refresh-utils/dist/ReactRefreshWebpackPlugin' import chalk from 'next/dist/compiled/chalk' import crypto from 'crypto' -import { builtinModules } from 'module' import { webpack } from 'next/dist/compiled/webpack/webpack' import path from 'path' import { escapeStringRegexp } from '../shared/lib/escape-regexp' @@ -1247,39 +1246,6 @@ export default async function getBaseWebpackConfig( // If the request cannot be resolved we need to have // webpack "bundle" it so it surfaces the not found error. if (!res) { - // We tried to bundle this request in the server layer but it failed. - // In this case we need to display a helpful error message for people to - // add the package to the `serverComponentsExternalPackages` config. - if (layer === WEBPACK_LAYERS.server && !request.startsWith('#')) { - if (/[/\\]node_modules[/\\]/.test(context)) { - // Built-in modules can be safely ignored. - if (!builtinModules.includes(request)) { - // Try to match the package name from the context path: - // - /node_modules/package-name/... - // - /node_modules/.pnpm/package-name@version/... - // - /node_modules/@scope/package-name/... - // - /node_modules/.pnpm/scope+package-name@version/... - const packageName = - context.match( - /[/\\]node_modules[/\\](\.pnpm[/\\])?([^/\\@]+)/ - )?.[2] || - context.match( - /[/\\]node_modules[/\\](@[^/\\]+[/\\][^/\\]+)[/\\]/ - )?.[2] || - context - .match( - /[/\\]node_modules[/\\]\.pnpm[/\\](@[^/\\@]+\+[^/\\@]+)/ - )?.[1] - ?.replace(/\+/g, '/') - - throw new Error( - `Failed to bundle ${ - packageName ? `package "${packageName}"` : context - } in Server Components because it uses "${request}". Please try adding it to the \`serverComponentsExternalPackages\` config: https://beta.nextjs.org/docs/api-reference/next.config.js#servercomponentsexternalpackages` - ) - } - } - } return } diff --git a/packages/next/src/client/dev/error-overlay/format-webpack-messages.ts b/packages/next/src/client/dev/error-overlay/format-webpack-messages.ts index d6e2f7d185e05..82a025f32f794 100644 --- a/packages/next/src/client/dev/error-overlay/format-webpack-messages.ts +++ b/packages/next/src/client/dev/error-overlay/format-webpack-messages.ts @@ -193,25 +193,18 @@ export default function formatWebpackMessages(json: any, verbose?: boolean) { }) // Reorder errors to put the most relevant ones first. - let reactServerComponentsBundleError = -1 let reactServerComponentsError = -1 for (let i = 0; i < formattedErrors.length; i++) { const error = formattedErrors[i] if (error.includes('ReactServerComponentsError')) { reactServerComponentsError = i - } - if (/Failed to bundle .+ in Server Components/.test(error)) { - reactServerComponentsBundleError = i + break } } - // Move the reactServerComponentsBundleError to the top, if it exists - // Otherwise, move the reactServerComponentsError to the top if it exists - if (reactServerComponentsBundleError !== -1) { - const error = formattedErrors.splice(reactServerComponentsBundleError, 1) - formattedErrors.unshift(error[0]) - } else if (reactServerComponentsError !== -1) { + // Move the reactServerComponentsError to the top if it exists + if (reactServerComponentsError !== -1) { const error = formattedErrors.splice(reactServerComponentsError, 1) formattedErrors.unshift(error[0]) }