Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next.js 15 - 'Cannot read properties of undefined (reading 'call')' Error When Exporting Functions with 'use server' Directive #1665

Open
1 task done
clickspider opened this issue Dec 14, 2024 · 0 comments

Comments

@clickspider
Copy link

Describe the bug

When using Next.js 15 with Node.js v18.20.3, I encounter an error:

[ Server ] Error: Cannot read properties of undefined (reading 'call')

This happens when I try to export functions from other files that have 'use server' at the top.

  • Changing the exported function from an arrow function to a normal function expression resolves the error temporarily.
  • However, restarting the server (via npm run dev) causes the same error to reappear, and I need to reverse the function type (e.g., from normal function expression to arrow function) for it to work again.

This creates a loop where I constantly have to toggle the function type after every server restart to avoid the error. It seems like a bug related to the use of 'use server' or the server's handling of function exports.

Link to the blitz that caused the error

https://stackblitz.com/~/github.com/clickspider/bolt-nextjs-subscription-payments/tree/debug-main-13

Steps to reproduce

  1. Create a file with a function export, e.g., using an arrow function, and add 'use server' at the top.
  2. Import this function into another file in a Next.js 15 project.
  3. Start the development server with npm run dev and observe the error: [ Server ] Error: Cannot read properties of undefined (reading 'call')
    1. Change the function to a normal function expression (instead of an arrow function).
  4. The error disappears.
  5. Restart the development server, and the error reappears.
  6. Repeat step 4, toggling the function type, and observe the same pattern.

Expected behavior

The exported function should work consistently without toggling between an arrow function and a normal function expression after every server restart.

Parity with Local

Screenshots

image

Platform

  • OS: macOS
  • Browser: Chrome
  • Version 131.0.6778.109 (Official Build) (arm64)

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant