diff --git a/packages/next/src/build/webpack/plugins/next-types-plugin.ts b/packages/next/src/build/webpack/plugins/next-types-plugin.ts index fe794b60cb7e1..1bcb85d0c95a5 100644 --- a/packages/next/src/build/webpack/plugins/next-types-plugin.ts +++ b/packages/next/src/build/webpack/plugins/next-types-plugin.ts @@ -220,15 +220,23 @@ export class NextTypesPlugin { return } + // Filter out non-page files in pages dir + if ( + !isApp && + /[/\\](?:_app|_document|_error|404|500)\.[^.]+$/.test(filePath) + ) { + return + } + const page = isApp ? normalizeAppPath(path.relative(this.appDir, filePath)) : '/' + path.relative(this.pagesDir, filePath) let route = (isApp - ? page.replace(/\/page\.[^./]+$/, '') - : page.replace(/\.[^./]+$/, '') - ).replace(/\/index$/, '') || '/' + ? page.replace(/[/\\]page\.[^./]+$/, '') + : page.replace(/\.[^./]+$/, '').replace(/[/\\]index$/, '') + ).replace(/\\/g, '/') || '/' if (isDynamicRoute(route)) { route = route