diff --git a/packages/next/lib/find-pages-dir.ts b/packages/next/lib/find-pages-dir.ts index 0de35966f5616..966766309cfb8 100644 --- a/packages/next/lib/find-pages-dir.ts +++ b/packages/next/lib/find-pages-dir.ts @@ -10,7 +10,7 @@ export const existsSync = (f: string): boolean => { } } -function findDir(dir: string, name: 'pages' | 'app'): string | null { +export function findDir(dir: string, name: 'pages' | 'app'): string | null { // prioritize ./${name} over ./src/${name} let curDir = path.join(dir, name) if (existsSync(curDir)) return curDir diff --git a/packages/next/server/dev/next-dev-server.ts b/packages/next/server/dev/next-dev-server.ts index cc34cfb70d123..c5c2f986039fb 100644 --- a/packages/next/server/dev/next-dev-server.ts +++ b/packages/next/server/dev/next-dev-server.ts @@ -305,7 +305,9 @@ export default class DevServer extends Server { ignored: (pathname: string) => { return ( !files.some((file) => file.startsWith(pathname)) && - !directories.some((dir) => pathname.startsWith(dir)) + !directories.some( + (dir) => pathname.startsWith(dir) || dir.startsWith(pathname) + ) ) }, })) diff --git a/packages/next/server/next-server.ts b/packages/next/server/next-server.ts index 5de216bb08dfa..ef5a0a3bfc325 100644 --- a/packages/next/server/next-server.ts +++ b/packages/next/server/next-server.ts @@ -48,6 +48,7 @@ import { FONT_LOADER_MANIFEST, } from '../shared/lib/constants' import { recursiveReadDirSync } from './lib/recursive-readdir-sync' +import { findDir } from '../lib/find-pages-dir' import { format as formatUrl, UrlWithParsedQuery } from 'url' import compression from 'next/dist/compiled/compression' import { getPathMatch } from '../shared/lib/router/utils/path-match' @@ -474,15 +475,7 @@ export default class NextNodeServer extends BaseServer { } protected getHasAppDir(dev: boolean): boolean { - const appDirectory = dev - ? join(this.dir, 'app') - : join(this.serverDistDir, 'app') - - try { - return fs.statSync(appDirectory).isDirectory() - } catch (err) { - return false - } + return Boolean(findDir(dev ? this.dir : this.serverDistDir, 'app')) } protected generateStaticRoutes(): Route[] { diff --git a/test/e2e/app-dir/app-alias/app/button/page.tsx b/test/e2e/app-dir/app-alias/src/app/button/page.tsx similarity index 100% rename from test/e2e/app-dir/app-alias/app/button/page.tsx rename to test/e2e/app-dir/app-alias/src/app/button/page.tsx diff --git a/test/e2e/app-dir/app-alias/app/layout.tsx b/test/e2e/app-dir/app-alias/src/app/layout.tsx similarity index 100% rename from test/e2e/app-dir/app-alias/app/layout.tsx rename to test/e2e/app-dir/app-alias/src/app/layout.tsx