Skip to content

Server actions regression in 14.2.8: “Failed to find Server Action” #69756

@controversial

Description

@controversial

When multiple components import from the same actions.ts file, server actions are missing/broken in the final build.

As seen in the attached repository, the structure I found which reliably reproduces this issue is as follows:

  • actions.ts (marked with 'use server') exports two server actions.
  • a page.tsx imports action1
  • this page also renders a child component, which imports action2 from the same file.

If page.tsx calls action1, the action will return undefined (instead of its real return value) and a “failed to find Server Action” error will appear in the server console:

Screenshot 2024-09-05 at 6 35 14 PM

Link to the code that reproduces this issue

https://github.com/controversial/next-server-actions-regression-repro

To Reproduce

Clone the included repository, then

  1. bun install
  2. bunx next build && bunx next start
  3. visit localhost:3000/my-page

Current vs. Expected behavior

Current behavior (next@canary and next@14.2.8)

  • Server console shows:
    Error: Failed to find Server Action "84eb9c473d392e3d69c580b53ac4d200bdc426c8". This request might be from an older or newer deployment. Original error: Cannot read properties of undefined (reading 'workers')
        ...
    
  • browser console shows: action1 returned: undefined

i.e. the server action is missing / broken

Expected behavior (next <= 14.2.7)

  • Server console shows no error when calling action1
  • Browser console shows action1 returned: {hello: 'world'}

i.e., all of the server actions that are imported from actions.ts get hooked up properly.

you can see this behavior by downgrading next to 14.2.7 within the included repro repository.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Fri Aug 16 19:18:30 PDT 2024; root:xnu-11215.40.42~4/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 22.7.0
  npm: 10.8.2
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 14.2.8 // Latest available version is detected (14.2.8).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.5.4
Next.js Config:
  output: N/A

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

Server actions, runtime, vercel deployments, app router

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

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

Additional context

  • This error also exists with the current next@canary (141)
    • I made the repro using 14.2.8 to show that the current “stable” version includes this regression, but you can change the package versions to observe that canary is broken but 14.2.7 is not.
  • This regression in server actions is affecting our production app on Vercel.
  • There are no issues in the dev server, only after a production build.
  • This regression was introduced in Apply optimization for unused actions #69178
    • Based on debugging the webpack plugin, it seems like webpack’s own moduleGraph.getOutgoingConnections() may be returning incomplete/incorrect information inside connection.dependency.ids

Metadata

Metadata

Assignees

Labels

RuntimeRelated to Node.js or Edge Runtime with Next.js.bugIssue was opened via the bug report template.locked

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions