next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Can not export class in action server (only async function)

Open Lucstay11 opened this issue 1 year ago • 1 comments

Verify canary release

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

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May  7 09:00:52 UTC 2
  Available memory (MB): 63931
  Available CPU cores: 12
Binaries:
  Node: 20.13.1
  npm: 10.5.2
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which example does this report relate to?

...

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

I can not export class and use it with server action...

Expected Behavior

I would like juste use the classe for OOP mvc for my app!

To Reproduce

My file form/action.ts

"use server" export class User{ async changeName(form:FormData) { const name = form.get("name") console.log(name) } }

My page.tsx

`import styles from "./page.module.css"; import {User} from "./form/action"

export default function Home() { const user = new User(); return ( <main className={styles.main}> <div className={styles.description}>

  <form action={user.changeName}>
    <input type="text" name="name"></input>
    <button type="submit">Change name</button>
  </form>
  </div>
</main>

); }`

Lucstay11 avatar Jun 07 '24 13:06 Lucstay11

This issue has been automatically marked as stale due to 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.

nextjs-bot avatar Dec 04 '25 23:12 nextjs-bot

This issue has been automatically closed due to inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!

nextjs-bot avatar Dec 12 '25 23:12 nextjs-bot