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

Server action in 18.2.6 vs 18.2.8 is not longer able to import server action in client component #69818

Closed
1 task done
pawanrana1992 opened this issue Sep 7, 2024 · 7 comments
Labels
locked please add a complete reproduction The issue lacks information for further investigation

Comments

@pawanrana1992
Copy link

pawanrana1992 commented Sep 7, 2024

Verify canary release

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

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32524
  Available CPU cores: 32
Binaries:
  Node: 20.14.0
  npm: N/A
  Yarn: N/A
  pnpm: 9.4.0
Relevant Packages:
  next: 14.2.8 // Latest available version is detected (14.2.8).
  eslint-config-next: 14.2.8
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.5.4
Next.js Config:
  output: N/A

Which example does this report relate to?

any fresh project

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

My project is running in 14.2.6 nextjs version and actions api working fine when importing into client component. But when updating to 14.2.8 version, I am getting import error

Error: Cannot access AuthTemplate.then on the server. You cannot dot into a client module from a server component. You can only pass the imported name through.
at Object.get (*\node_modules.pnpm\next@14.2.8_@babel+core@7.25.2_react-dom@18.3.1_react@18.3.1__react@18.3.1\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:12:125427) {
digest: '815452591'
}

I validate the Server action import with 18.2.8 version in client component using "use client" and in actions file "use server".
The same is working fine in 18.2.6 but not in 18.2.8 version.

and I have to revert my app to again 18.2.6 to work as expected.

Expected Behavior

The actions functions should import in client component smoothly without any error, as per documentations.

To Reproduce

  1. create a project with nextjs 18.2.8 version
  2. create file which will use server actions with "use server" as required
  3. Add any 2 server actions and export as object = ( export const abcAction and efgAction) with full action api return logic and data handeling
  4. Create a client side component "use client"
  5. Import the action in the client component
  6. run the app

You will see the error

Change the nextjs version to 18.2.6

  1. create a project with nextjs 18.2.6 version
  2. create file which will use server actions with "use server" as required
  3. Add any 2 server actions and export as object = ( export const abcAction and efgAction) with full action api return logic and data handeling
  4. Create a client side component "use client"
  5. Import the action in the client component
  6. run the app => It will work without any error
@pawanrana1992 pawanrana1992 added the examples Issue/PR related to examples label Sep 7, 2024
@fabicsp
Copy link

fabicsp commented Sep 7, 2024

For me had something similar issue:
I have upgrade from 14.2.7 => 14.2.8, and locally had no problems with the prod build, but at staging the server actions returned some html response, and was messed up everything.

@terrymun
Copy link

terrymun commented Sep 8, 2024

You aren't the only one affected by this issue, and it does not seem to be exclusive to server actions.

We have an in-house component library that uses the same compound component compoisiton pattern like you see in Radix UI, e.g. <Form.Control>, and this seems to be causing issues with the latest version of 14.2.8 when building. Downgrading back to 14.2.7 causes the build step to work.

▲ Next.js 14.2.8
- Experiments (use with caution):
  · outputFileTracingRoot

  Creating an optimized production build ...
✓ Compiled successfully
  Skipping linting
✓ Checking validity of types    
  Collecting page data  ...Error: Cannot access Form.Control on the server. You cannot dot into a client module from a server component. You can only pass the imported name through.
  at Object.get (<PROJECT_ROOT>/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:125427)
  at <PROJECT_ROOT>/dist/apps/portal/.next/server/chunks/9394.js:1:7411
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Error: Cannot access Form.Control on the server. You cannot dot into a client module from a server component. You can only pass the imported name through.
  at Object.get (<PROJECT_ROOT>/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:125427)
  at <PROJECT_ROOT>/dist/apps/portal/.next/server/app/sitemap.xml/route.js:134:10521
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I've checked through our code and removed all references to <Form.Control> in our code in an attempt to debug the issue, but the issue still appears.

@huozhi huozhi added please add a complete reproduction The issue lacks information for further investigation and removed examples Issue/PR related to examples labels Sep 9, 2024
@huozhi
Copy link
Member

huozhi commented Sep 9, 2024

The error message looks like gonna be fixed in #69749 and we will release a patch to get it fixed. I still like to ask for a reproduction that can help us reproduce it. It could either be a missing case or bad usage that might require changes in the future.

Copy link
Contributor

github-actions bot commented Sep 9, 2024

We cannot recreate the issue with the provided information. Please add a reproduction in order for us to be able to investigate.

Why was this issue marked with the please add a complete reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository (template for App Router, template for Pages Router), but you can also use these templates: CodeSandbox: App Router or CodeSandbox: Pages Router.

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

Please test your reproduction against the latest version of Next.js (next@canary) to make sure your issue has not already been fixed.

If you cannot create a clean reproduction, another way you can help the maintainers' job is to pinpoint the canary version of next that introduced the issue. Check out our releases, and try to find the first canary release that introduced the issue. This will help us narrow down the scope of the issue, and possibly point to the PR/code change that introduced it. You can install a specific version of next by running npm install next@<version>.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

What happens if I don't provide a sufficient minimal reproduction?

Issues with the please add a complete reproduction label that receives no meaningful activity (e.g. new comments with a reproduction link) are automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the 👍 reaction on the topmost comment (please do not comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren't you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

@huozhi
Copy link
Member

huozhi commented Sep 9, 2024

We patched a fix in 14.2.9, if it's the same issue with #69720, please upgrade to the new version 🙏 I'll close this one for now, if it's a different issue, please submit with a full reproduction, thanks.

@huozhi huozhi closed this as completed Sep 9, 2024
@terrymun
Copy link

terrymun commented Sep 9, 2024

@huozhi Can confirm that upgrading to 14.2.9 fixes this.

The curious thing is, we are not using compound components anywhere in our server actions, so I wonder how #69720 fixed the bug... but I'm not complaining as the build works now :) thanks again!

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked please add a complete reproduction The issue lacks information for further investigation
Projects
None yet
Development

No branches or pull requests

4 participants