TheEdoRan / next-safe-action

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

[BUG] not able to get an instance of actionClient #124

Closed B33fb0n3 closed 4 months ago

B33fb0n3 commented 4 months ago

Are you using the latest version of this library?

Is there an existing issue for this?

Describe the bug

When I install next-safe-action via pnpm add next-safe-action everything is fine. When I now add the correct code from the documentation inside my safe-action.ts:

import { createSafeActionClient } from "next-safe-action";

export const actionClient = createSafeActionClient();

I will get the following error: TS2742: The inferred type of actionClient cannot be named without a reference to .pnpm/@decs+typeschema@0.12.2_zod@3.23.8/node_modules/@decs/typeschema . This is likely not portable. A type annotation is necessary.

It seems like it's not typed correctly. How to resolve that?

Reproduction steps

  1. Install via pnpm add next-safe-action
  2. Add the file safe-action.ts
  3. Paste the following code:
    
    import { createSafeActionClient } from "next-safe-action";

export const actionClient = createSafeActionClient();


4. See the error.
![image](https://github.com/TheEdoRan/next-safe-action/assets/65173484/fe6b212e-ca25-44a9-af31-09307e156294)

### Expected behavior

Normally, I would create a safeActionClient.

### Reproduction example

-

### Operating System

Windows 11

### Library version

^6.2.0

### Additional context

I saw, that it seems like a local problem, but I still don't know how to resolve it... 🤔 
Thanks for your help <3
TheEdoRan commented 4 months ago

Does this solve your issue?

B33fb0n3 commented 4 months ago

Yes, that solved the issue. Thanks! I saw, that I am using .d.ts files. What will happen to them? It seems right now to not have any impact, but maybe in the future?

TheEdoRan commented 4 months ago

It seems right now to not have any impact, but maybe in the future?

That seems to be a TypeScript issue with pnpm, and it affects multiple projects, so unfortunately I don't have an answer for that. However, I think that next-safe-action v7 could solve this issue, since it's a complete rewrite of the library. I recommend to install next-safe-action@next for upcoming v7 to see if the error goes away. Docs are updated and can be found here. I'm just waiting for Next.js 14.3.0 stable release to merge next branch into main. Hope this helps!

B33fb0n3 commented 4 months ago

I tried to fix it using the v7 version, but the issue still persists. Maybe it's fixed in the future, because I love this next-safe-action ^^

hannanstd commented 1 month ago

https://github.com/TheEdoRan/next-safe-action/issues/124#issuecomment-2110172864 It worked for me, thanks