vercel / vercel/next.js

Turbopack causes `req instanceof NextRequest` to fail in `nodejs` middleware

Open
#83,116 2 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

linear: turbopack Middleware Turbopack
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/SimonVadier/repro-turbopack-nodejs-middleware

To Reproduce
  1. Start the application with next dev
  2. Visit the app
  3. Observe console log Request is an instance of NextRequest
  4. Start the application with next dev --turbopack
  5. Visit the app
  6. Observe console log Request is not an instance of NextRequest
Current vs. Expected behavior

When using Turbopack in dev mode, request instanceof NextRequest returns false in a nodejs middleware, while it returns true with the standard dev server. This is problematic because some libraries rely on this check to determine how to process the request object. (https://github.com/auth0/nextjs-auth0/issues/2253)

The request object provided by Turbopack seems to have the same shape and functionality as NextRequest, but it fails the instanceof check.

Provide environment information
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Thu Aug 21 06:22:32 EDT 2025
  Available memory (MB): 15732
  Available CPU cores: 12
Binaries:
  Node: 24.5.0
  npm: 11.5.1
  Yarn: 1.22.22
  pnpm: 10.14.0
Relevant Packages:
  next: 15.5.2 // Latest available version is detected (15.5.2).
  eslint-config-next: N/A
  react: 19.1.1
  react-dom: 19.1.1
  typescript: N/A
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)

Additional context

No response

PACK-5361

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 Turbopack reproduction and compare next dev with next dev --turbopack for the nodejs middleware case. Trace where the middleware request is constructed, then verify that req instanceof NextRequest is true under both dev servers and add a regression test if the relevant test location is found.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, nodejs
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.