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

getErrorFromUnknown mismatch TRPCError when bundler minified the TRPCError class #12

Open
NotEvenANeko opened this issue Jul 26, 2023 · 0 comments

Comments

@NotEvenANeko
Copy link

NotEvenANeko commented Jul 26, 2023

Vite with build.minify on will minified the name of TRPCError so cause instanceof Error && cause.name === 'TRPCError' in getErrorFromUnknown will always get false.

So if I throw a TRPCError in procedure and handle it in onError option, the opts.error will be a TRPCError with code === 'INTERNAL_SERVER_ERROR' and the cause in my error.

This is the first issue, and next section might be second issue but...I just write it here.

After I patched getErrorFromUnknown with (cause instanceof Error && cause.name === 'TRPCError') || cause instance TRPCError (server_1.TRPCError in compiled outputs), I found out that the TRPCError from error.js and my code through import { TRPCError } from '@trpc/server' is not the same TRPCError...

It might be because the compiled outputs is in CommonJS which require the @trpc/server and I imported the @trpc/server with ESModule import, vite bundled both TRPCError of them, two different TRPCError-s.

Having an esm output might be helpful.

Dependencies:

  • @trpc/server: 10.33.0
  • trpc-chrome: 1.0.0
  • vite: 4.3.8
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

No branches or pull requests

1 participant