Skip to content

turbopack: don't generate implicit app not-found entrypoints for empty app directories - #1

Draft
thsid wants to merge 1 commit into
codex/fix-pages-404-empty-app-dirfrom
codex/fix-pages-404-turbopack-build
Draft

turbopack: don't generate implicit app not-found entrypoints for empty app directories#1
thsid wants to merge 1 commit into
codex/fix-pages-404-empty-app-dirfrom
codex/fix-pages-404-turbopack-build

Conversation

@thsid

@thsid thsid commented Jul 12, 2026

Copy link
Copy Markdown
Owner

What?

This fixes an inconsistency in Turbopack production builds where an app directory with no actual routes would still generate implicit _not-found and _global-error entrypoints.

As a result, a custom pages/404 could be incorrectly shadowed by the App Router's built-in not-found page, even though the App Router wasn't actually being used.

This brings next build --turbopack in line with the existing webpack/dev behavior introduced in vercel#95713.

Why?

The Turbopack app entrypoint collection always generated implicit not-found/global-error entrypoints whenever an app directory existed, regardless of whether that directory contained any real routes.

This differed from the webpack logic, which only treats an app directory as active when it actually contains route files.

As a result, projects that primarily use the Pages Router—but still have an empty app directory (for example, after an abandoned App Router migration)—would unexpectedly lose their custom pages/404.

How?

  • Added directory_tree_has_any_route, which recursively checks whether an app directory tree contains any real route (page, route, not-found, or global-not-found).
  • Skip generating implicit _not-found and _global-error entrypoints when no routes exist anywhere in the tree.
  • Removed the temporary it.failing expectations from the regression test since Turbopack production builds now behave correctly.
  • This mirrors the logic introduced in fix(next-dev): don't let an app dir without real routes override pages/404 vercel/next.js#95713 for webpack/dev, keeping both implementations consistent.

Testing

  • cargo check -p next-core
  • cargo clippy -p next-core --no-deps
  • Verified test/e2e/app-dir/pages-404-with-empty-app-dir passes in all four modes:
    • next dev (webpack)
    • next dev --turbopack
    • next build (webpack)
    • next build --turbopack
  • Verified not-found-with-pages-i18n continues to behave correctly, including in Turbopack production builds.
  • Observed an intermittent timeout in not-found/basic, but confirmed it reproduces on the baseline without this change and is unrelated.

Depends on vercel#95713

An `app` directory that exists but has no real routes anywhere in it
still got an implicit `_not-found`/`_global-error` route from
Turbopack's app-dir entrypoint discovery, which shadowed a custom
`pages/404` in production builds (`next build --turbopack`). The
webpack/dev-mode fix in vercel#95713 didn't cover this path since Turbopack's
production build enumerates app-dir entrypoints independently on the
Rust side.

Also flips the two Turbopack-production-build test cases in
pages-404-with-empty-app-dir.test.ts from `it.failing` back to `it`,
since this fix resolves them.

Depends on vercel#95713.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant