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

Serverless Functions are Treated as Client-Side (Next.js 13, Latest Release) #43244

Open
1 task done
gregfromstl opened this issue Nov 22, 2022 · 1 comment
Open
1 task done
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.

Comments

@gregfromstl
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000
Binaries:
Node: 16.13.2
npm: 8.1.2
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 13.0.5-canary.4
eslint-config-next: 13.0.4
react: 18.2.0
react-dom: 18.2.0

What browser are you using? (if relevant)

Chrome Version 107.0.5304.110

How are you deploying your application? (if relevant)

No response

Describe the Bug

I'm trying to make a user action trigger some server-side code run on serverless functions. When I import "server-only" to my serverless function (or any other server-only import), then call it from a client-side component, it throws an error saying the serverless function in the API directory is a child of my client component and is therefore client-side.

Expected Behavior

Serverless functions in the API directory should not be run client-side and should not throw an error when called through an API request from a client-side component.

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://github.com/gregfromstl/serverless-runs-client-side

To Reproduce

Start the application, then click the button labeled "Click Me".

To reproduce in a new project, just install "server-only", then import it to any serverless function in the api directory. Create a client-side component with "use client", a function that calls the serverless function using fetch, and a trigger within that component such as an onClick. Then, trigger the API call to view the error.

@gregfromstl gregfromstl added the bug Issue was opened via the bug report template. label Nov 22, 2022
@vercel-release-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@vercel-release-bot vercel-release-bot added the stale The issue has not seen recent activity. label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

2 participants