Skip to content

404 Template Throws 500 Error when Using Middleware (v14.2.7) #69428

@tjdunklee

Description

@tjdunklee

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/jolly-taussig-tzm55f

To Reproduce

  1. View the repro CodeSandbox
  2. Try to visit any page that has a invalid url
  3. Notice the 500 error.

Current vs. Expected behavior

I would expect the custom 404 template to be displayed, instead a 500 error is thrown. This only seems to happen if a Middleware file is present. This seemed to start with v14.2.7.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 14.2.7 // Latest available version is detected (14.2.7).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.1.3
Next.js Config:
  output: N/A

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

Middleware

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

next dev (local), next build (local), Other (Deployed)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    MiddlewareRelated to Next.js Middleware.bugIssue was opened via the bug report template.linear: nextConfirmed issue that is tracked by the Next.js team.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions