vercel / vercel/next.js

500 errors when sending OPTIONS request to _next/static/chunks/...

Open
#92,141 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

create-next-app Headers Metadata Output Route Handlers
Dominant language
JavaScript
Stars
142k
Forks
32.5k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/djalabs/nextjs-reproduction-app

To Reproduce

Start the application in production mode (npm run build && npm run start)
Open localhost:3000 and filter network tab of dev console for _next/static/chunks
Send OPTIONS request to one of those URLs instead of GET and note that you get a 500 error

Current vs. Expected behavior

500 errors should always be considered a bug somewhere in the code, as potentially malicious or broken clients should not be able to trigger them arbitrarily. Currently it is polluting our HTTP logs with noise and makes up the almost all of our 500 errors in production.

OPTIONS request should really be handled without any error, but if an error must be given then 405 or something else in the 4XX range would be much less frustrating.

Provide environment information
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 32190
  Available CPU cores: 16
Binaries:
  Node: 22.14.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 16.2.1-canary.14 // Latest available version is detected (16.2.1-canary.14).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: N/A

Note that the same issue occurs on our GCP cloud run production instance
Which area(s) are affected? (Select all that apply)

Route Handlers, create-next-app, Output, Metadata, Headers

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

Other (Deployed), next start (local)

Additional context

Wasn't really sure what to put for areas affected, but basically just about all nextjs instances out in the wild can be tricked into 500-ing, and we have seen that certain questionable bots will do this automatically, whether intentional or not.

Initially created with direct link to reproduction template within nextjs, since no code changes needed to reproduce this error, but bot didn't like that so recreating with our own repo.

Overlaps with #75668 but IMO even worse as at least 4XXs are generally treated as warnings and do not escalate into error logs. Dev just gives the 400 errors, only prod build/start gives 500 errors.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked djalabs/nextjs-reproduction-app and reproduce the issue using npm run build && npm run start, then inspect how production next start handles OPTIONS requests for _next/static/chunks URLs. Done means those requests no longer produce 500 responses, with the behavior verified locally and on the reported deployed setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js
Domain
backend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.