Skip to content

Custom 404 in pages router not work as expected when using both pages router and app router #82229

@yunsii

Description

@yunsii

Link to the code that reproduces this issue

https://github.com/yunsii/nextjs-custom-errors-reproduction

To Reproduce

  1. next dev
  2. return custom 404 as expected when opening http://localhost:3000/404
  3. return default 404 when opening http://localhost:3000/404-in-page-router is not what we expected

When I rename app dir to others name and restart server, it will return custom 404 when opening http://localhost:3000/404-in-page-router

Also I tried to use /app/not-found.page.tsx, and opening http://localhost:3000/404-in-page-router will encounter error:

> [email protected] dev /home/yuns/work/hello-next
> next dev

   ▲ Next.js 15.4.5
   - Local:        http://localhost:3000
   - Network:      http://10.255.255.254:3000

 ✓ Starting...
 ✓ Ready in 1371ms
 ○ Compiling /404-in-page-router ...
 ✓ Compiled /404-in-page-router in 606ms (281 modules)
 ○ Compiling /_not-found ...
 ✓ Compiled /_not-found in 1029ms (858 modules)
 ⨯ [Error [InvariantError]: Invariant: Expected clientReferenceManifest to be defined. This is a bug in Next.js.]
 ⨯ [Error [InvariantError]: Invariant: Expected clientReferenceManifest to be defined. This is a bug in Next.js.]
 ✓ Compiled /_error in 383ms (931 modules)
 GET /404-in-page-router 500 in 3578ms

Current vs. Expected behavior

Return consistent 404 page in pages router.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025
  Available memory (MB): 58254
  Available CPU cores: 20
Binaries:
  Node: 22.15.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.12.4
Relevant Packages:
  next: 15.4.5 // Latest available version is detected (15.4.5).
  eslint-config-next: 15.4.5
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Error Handling, Pages Router

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error HandlingRelated to handling errors (e.g., error.tsx, global-error.tsx).Pages RouterRelated to Pages Router.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions