From dba9383b91aaaa4cad2659748ba203ba013512a2 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 23 Oct 2024 23:59:44 +0200 Subject: [PATCH] fix undefined default export error msg --- .../src/server/app-render/create-component-tree.tsx | 3 ++- .../acceptance-app/undefined-default-export.test.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/next/src/server/app-render/create-component-tree.tsx b/packages/next/src/server/app-render/create-component-tree.tsx index d355c052a0a36..a388b7e20ec1b 100644 --- a/packages/next/src/server/app-render/create-component-tree.tsx +++ b/packages/next/src/server/app-render/create-component-tree.tsx @@ -53,8 +53,9 @@ function errorMissingDefaultExport( pagePath: string, convention: string ): never { + const normalizedPagePath = pagePath === '/' ? '' : pagePath throw new Error( - `The default export is not a React Component in "${pagePath}/${convention}"` + `The default export is not a React Component in "${normalizedPagePath}/${convention}"` ) } diff --git a/test/development/acceptance-app/undefined-default-export.test.ts b/test/development/acceptance-app/undefined-default-export.test.ts index 9cc391a5cf719..c71dcd3d30c24 100644 --- a/test/development/acceptance-app/undefined-default-export.test.ts +++ b/test/development/acceptance-app/undefined-default-export.test.ts @@ -49,6 +49,19 @@ describe('Undefined default export', () => { }) it('should error when page component export is not valid', async () => { + const { session, cleanup } = await sandbox(next, undefined, '/') + + await next.patchFile('app/page.js', 'const a = 123') + + await session.assertHasRedbox() + expect(await session.getRedboxDescription()).toInclude( + 'The default export is not a React Component in "/page"' + ) + + await cleanup() + }) + + it('should error when root page component export is not valid', async () => { const { session, cleanup } = await sandbox( next, undefined,