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

Does not work in ESM #7

Closed
kran6a opened this issue May 31, 2024 · 3 comments · Fixed by #8
Closed

Does not work in ESM #7

kran6a opened this issue May 31, 2024 · 3 comments · Fixed by #8

Comments

@kran6a
Copy link
Contributor

kran6a commented May 31, 2024

Reproduction

import {initTRPC} from '@trpc/server';
import {z} from 'zod';
import {trpcCli} from 'trpc-cli';

const t = initTRPC.create();

export const router = t.router({
    add: t.procedure
        .input(z.object({left: z.number(), right: z.number()}))
        .query(({input}) => input.left + input.right),
});

const cli = trpcCli({router});
await cli.run();

If you add console.log({parsedArgv}) on trpc-cli index.ts you can see why it does not work:

[
  [
    "add",
    "Invalid input type ZodObject, only zod inputs are supported"
  ]
]

Apparently import {z} from "zod" and require("zod") are not importing the same classes thus instanceof does not work as intended.

@mmkal
Copy link
Owner

mmkal commented May 31, 2024

Interesting, sounds like zod has the dual-package hazard. Probably can be worked around by making a helper function with a guard return type, which checks the constructor name or something.

@mmkal mmkal mentioned this issue May 31, 2024
@mmkal
Copy link
Owner

mmkal commented May 31, 2024

@kran6a I just published a prerelease version which should help with this. You can install with npm install [email protected].

I was able to repro the issue and that the new version fixes. #8. Could you try it out?

@kran6a
Copy link
Contributor Author

kran6a commented Jun 1, 2024

It works! Thanks for the quick fix

@mmkal mmkal closed this as completed in #8 Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants