next.js: Server actions regression in 14.2.8: “Failed to find Server Action”

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 #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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 18
  • Comments: 19 (7 by maintainers)

Most upvoted comments

We released v14.2.10 with the fix, could you upgrade to the latest version and verify if that fixed for you? 🙏 Thanks

I encountered the same issue, which was working fine with 14.2.7. After some investigation, I found a solution by changing the way I export server actions in my index.ts file.

Before:

index.ts

export * from './user/create-user';
export * from './auth/login';

After:

index.ts

export { createUser } from './user/create-user';
export { authenticate, login } from './auth/login';

The wildcard export (export *) seemed to cause problems with server actions, but explicitly naming the exports resolved the issue. This way, I was able to maintain the imports like this:

import { authenticate, login } from '@actions';

without having to reference the full path to the server action.

I hope this helps anyone facing a similar problem!

Note. My directory structure looks something like this:

.
└── src/
    ├── actions/
    │   ├── user/
    │   │   └── create-user.ts
    │   ├── auth/
    │   │   └── login.ts
    │   └── index.ts
    └── app/
        └── auth/
            └── login/page.tsx

Folks, we had a fix in patch release 14.2.9, please upgrade and let us know if it fixed for you 🙏

Server actions work well in 14.2.10 and 14.2.11.

@huozhi I’ve upgraded to version 14.2.9, but still receiving this error which seems related to this issue, the server action I’m using is structured as in https://sdk.vercel.ai/examples/next-app/assistants/stream-assistant-responses.

When downgrading to v14.2.7, I’m not receiving this error.

I’m not sure if this is related to the ai package, or a change in next, when I upgrade either one of those, the AI functionality in my production app breaks.

I’ve logged a ticket on the ai package: https://github.com/vercel/ai/issues/2948

Reproduction can be found here: https://github.com/WoetDev/bug-next-ai-sdk

image

I just ran into this issue as well.

I encountered the same issue, which was working fine with 14.2.7. After some investigation, I found a solution by changing the way I export server actions in my index.ts file.

Before:

index.ts

export * from './user/create-user';
export * from './auth/login';

After:

index.ts

export { createUser } from './user/create-user';
export { authenticate, login } from './auth/login';

The wildcard export (export *) seemed to cause problems with server actions, but explicitly naming the exports resolved the issue. This way, I was able to maintain the imports like this:

import { authenticate, login } from '@actions';

without having to reference the full path to the server action.

I hope this helps anyone facing a similar problem!

Note. My directory structure looks something like this:

.
└── src/
    ├── actions/
    │   ├── user/
    │   │   └── create-user.ts
    │   ├── auth/
    │   │   └── login.ts
    │   └── index.ts
    └── app/
        └── auth/
            └── login/page.tsx

I was having issues, but I tried this solution, and now all the server actions work with version 14.2.9. A bit strange behavior, as with version 14.2.7, everything was working fine with the export * from ‘./file’.

Does anyone know the reason why? Or is it just an issue?