Skip to content

Commit 9d1fbbc

Browse files
authored
ignore .d.ts files inside pages folder (#30728)
Fixes #30698 and #30618 ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added
1 parent d72f5bd commit 9d1fbbc

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

packages/next/build/entries.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ export function createPagesMapping(
3636
}
3737
): PagesMapping {
3838
const previousPages: PagesMapping = {}
39+
40+
// Do not process .d.ts files inside the `pages` folder
41+
pagePaths = extensions.includes('ts')
42+
? pagePaths.filter((pagePath) => !pagePath.endsWith('.d.ts'))
43+
: pagePaths
44+
3945
const pages: PagesMapping = pagePaths.reduce(
4046
(result: PagesMapping, pagePath): PagesMapping => {
4147
let page = pagePath.replace(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const container: string

test/integration/404-page/test/index.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ const runTests = (mode = 'server') => {
3838
expect(res.status).toBe(404)
3939
})
4040

41+
it('should use pages/404 for .d.ts file', async () => {
42+
const html = await renderViaHTTP(appPort, '/invalidExtension')
43+
expect(html).toContain('custom 404 page')
44+
})
45+
4146
it('should not error when visited directly', async () => {
4247
const res = await fetchViaHTTP(appPort, '/404')
4348
expect(res.status).toBe(404)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const container: string

test/integration/page-extensions/test/index.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,17 @@ describe('Page Extensions', () => {
6464
'@zeit/next-typescript is no longer needed since Next.js has built-in support for TypeScript now'
6565
)
6666
})
67+
68+
it('should not throw if .d.ts file inside the pages folder', async () => {
69+
await fs.writeFile(
70+
nextConfig,
71+
`module.exports = { pageExtensions: ['js', 'ts', 'tsx'] }`
72+
)
73+
74+
const { stdout } = await runNextCommand(['build', appDir], { stdout: true })
75+
76+
await fs.remove(nextConfig)
77+
78+
expect(stdout).toContain('Compiled successfully')
79+
})
6780
})

0 commit comments

Comments
 (0)