vercel / vercel/next.js

Server Actions return 404 when proxy.ts (middleware) is present with --experimental-build-mode compile

Open
#94,989 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Middleware Output Server Actions
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/mrpackethead/nextjs-compile-mode-server-actions-repro

To Reproduce
  1. Clone the reproduction repo: git clone https://github.com/mrpackethead/nextjs-compile-mode-server-actions-repro
  2. npm install
  3. Build with compile mode: npx next build --experimental-build-mode compile
  4. Start the standalone server: HOSTNAME=0.0.0.0 PORT=3000 node .next/standalone/server.js
  5. Test the server action with curl using the Next-Action header from the manifest
  6. Observe: 404 response with "Failed to find Server Action"
  7. Now remove src/proxy.ts, rebuild with same command, restart — server action returns 200
Current vs. Expected behavior

Current: When src/proxy.ts is present and the project is built with --experimental-build-mode compile, all Server Actions return 404 at runtime. The server-reference-manifest.json is generated correctly (action IDs and encryption key present), but the runtime cannot resolve actions through the middleware layer.

Expected: Server Actions should work correctly with --experimental-build-mode compile regardless of whether proxy.ts is present. The combination of these two features should not break action routing.

Evidence matrix:

  • No proxy.ts + compile mode = Server Actions WORK
  • proxy.ts + compile mode = Server Actions 404
  • proxy.ts + full build = Server Actions WORK
Provide environment information
Operating System:
  Platform: linux
  Arch: x64
Node: 22.x
npm: 10.x
Relevant Packages:
  next: 16.2.6
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: standalone
Which area(s) are affected? (Select all that apply)

Middleware, Server Actions, Output

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

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

Additional context

This is the same class of bug as #86753 where proxy.js is not handled correctly in compile mode output.

We are deploying on AWS ECS Fargate with output: "standalone". The compile mode is used to separate the build into a compile step (in CI, no network access) and a generate step (in-VPC with data access). The bug affects any self-hosted deployment using this pattern with middleware/proxy.

The reproduction is a minimal Next.js app with a single server action and a trivial proxy.ts that just calls NextResponse.next(). No external dependencies needed to reproduce.

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

Clone the linked reproduction repo and run npx next build --experimental-build-mode compile, then start the standalone server and test the Server Action. Compare the generated server-reference-manifest.json and runtime behavior with and without src/proxy.ts, using #86753 as related context. Done means the action returns 200 with proxy.ts present in compile mode.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js
Domain
backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.