TheEdoRan / next-safe-action

Type safe and validated Server Actions in your Next.js (App Router) project.

Home Page:https://next-safe-action.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] not able to get an instance of actionClient

B33fb0n3 opened this issue · comments

Are you using the latest version of this library?

  • I verified that the issue exists in the latest next-safe-action release

Is there an existing issue for this?

  • I have searched the existing issues and found nothing that matches

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();
  1. See the error.
    image

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

Does this solve your issue?

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?

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!

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 ^^