TheEdoRan / next-safe-action

Type safe and validated Server Actions in your Next.js project.
https://next-safe-action.dev
MIT License
2.29k stars 35 forks source link

[BUG] Attempted import error: 'useActionState' is not exported from 'react' #203

Closed holahoon closed 3 months ago

holahoon commented 3 months ago

Are you using the latest version of this library?

Is there an existing issue for this?

Describe the bug

When building next.js, it fails to compile with error:

  ▲ Next.js 14.2.5
  - Environments: .env.production

   Creating an optimized production build ...
Failed to compile.

./node_modules/.pnpm/next-safe-action@7.2.0_next@14.2.5_react-dom@18.3.1_react@18.3.1_yup@1.4.0_zod@3.23.8/node_modules/next-safe-action/dist/stateful-hooks.mjs
Attempted import error: 'useActionState' is not exported from 'react' (imported as 'React').

Import trace for requested module:
./node_modules/.pnpm/next-safe-action@7.2.0_next@14.2.5_react-dom@18.3.1_react@18.3.1_yup@1.4.0_zod@3.23.8/node_modules/next-safe-action/dist/stateful-hooks.mjs
./node_modules/.pnpm/next-safe-action@7.2.0_next@14.2.5_react-dom@18.3.1_react@18.3.1_yup@1.4.0_zod@3.23.8/node_modules/next-safe-action/dist/hooks.mjs
./src/app/(main)/(auth)/reset-password/_components/reset-password-form.tsx

Reproduction steps

I deleted pnpm-lock.yaml and node_modules folders to clean install the package again. Ran pnpm install to install all of my dependencies and ran pnpm next run build to build the code. All of a sudden, build fails which wasn't failing before. Am I using a wrong version?

Expected behavior

Expected the build to compile, but fails with Attempted import error: 'useActionState' is not exported from 'react' (imported as 'React').

Minimal reproduction example

private repo

Operating System

mac OS M2

Library version

7.2.0

Next.js version

14.2.4

Additional context

No response

holahoon commented 3 months ago

I previously used 7.0.2 version, then updated to 7.2.0 to see if it solves, but no luck

holahoon commented 3 months ago

Ah, https://github.com/TheEdoRan/next-safe-action/issues/113

TheEdoRan commented 3 months ago

next-safe-action v7 works with Next.js 14 too. I mistakenly exported useStateAction hook from /hooks path in v7.2.0, while it should only be exported from /stateful-hooks path. v7.2.1 should fix this build issue, please let me know.

holahoon commented 3 months ago

Hmm, well, it seems like it Next.js requires React >= 19.0.0 when updating the Next.js version to 14.3.0-canary.40 which I don't want to use 19 yet 🤔

TheEdoRan commented 3 months ago

Can't you use Next 14.2.5?

holahoon commented 3 months ago

https://github.com/TheEdoRan/next-safe-action/releases/tag/v7.2.1 fixed it. Thanks!

holahoon commented 3 months ago

Can't you use Next 14.2.5?

Yeah, I def can. I just thought I had to upgrade to 14.3.0-canary.40 which requires react >=19.