Skip to content

Commit

Permalink
fix undefined default export error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Oct 23, 2024
1 parent 54768ac commit dba9383
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`
)
}

Expand Down
13 changes: 13 additions & 0 deletions test/development/acceptance-app/undefined-default-export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dba9383

Please sign in to comment.