diff --git a/packages/next/src/server/dev/log-app-dir-error.ts b/packages/next/src/server/dev/log-app-dir-error.ts index 7247b192f4c0d..a4c0a3314b641 100644 --- a/packages/next/src/server/dev/log-app-dir-error.ts +++ b/packages/next/src/server/dev/log-app-dir-error.ts @@ -3,12 +3,11 @@ import * as Log from '../../build/output/log' export function logAppDirError(err: any) { if (isError(err) && err?.stack) { - const filteredStack = err.stack - .split('\n') - .map((line: string) => - // Remove 'webpack-internal:' noise from the path - line.replace(/(webpack-internal:\/\/\/|file:\/\/)(\(.*\)\/)?/, '') - ) + const cleanedStack = err.stack.split('\n').map((line: string) => + // Remove 'webpack-internal:' noise from the path + line.replace(/(webpack-internal:\/\/\/|file:\/\/)(\(.*\)\/)?/, '') + ) + const filteredStack = cleanedStack // Only display stack frames from the user's code .filter( (line: string) => @@ -16,8 +15,12 @@ export function logAppDirError(err: any) { !/node_modules[\\/]/.test(line) && !/node:internal[\\/]/.test(line) ) - .join('\n') - Log.error(filteredStack) + if (filteredStack.length === 1) { + // This is an error that happened outside of user code, keep full stack + Log.error(`Internal error: ${cleanedStack.join('\n')}`) + } else { + Log.error(filteredStack.join('\n')) + } if (typeof (err as any).digest !== 'undefined') { console.error(`digest: ${JSON.stringify((err as any).digest)}`) }