-
Notifications
You must be signed in to change notification settings - Fork 14
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
bug: TRPCClientError: Invalid URL #23
Comments
Hi @maloguertin ... could we brainstorm some solutions to this issue please 🙏 |
Hey there! You found any solution for this issue? |
I managed to resolve this issue, but ran into another. Effectively the workaround is to set the trpc base url to be an arbitrary value. e.g. // utils/trpc.ts
import { httpBatchLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import type { AppRouter } from "@server/trpc/routers/_app";
function getBaseUrl() {
if (process.env.NODE_ENV === "test") return "http://localhost:3000";
if (typeof window !== "undefined") return "";
if (process.env.NEXTAUTH_URL) return process.env.NEXTAUTH_URL;
return `https://localhost:${process.env.PORT ?? 5001}`;
}
export const trpc = createTRPCNext<AppRouter>({
config(opts) {
return {
links: [
httpBatchLink({
url: `${getBaseUrl()}/api/internal`,
}),
],
};
},
ssr: false,
}); // test.ts
const server = setupServer(
rest.get("http://localhost:3000/api/trpc/getData", (req, res, ctx) => {
return res(ctx.json([]));
}),
); However, now I get another error:
Which I'm not sure what the issue is, but may be related to some kind've polyfilling, or requests firing before MSW can register. Not really sure though. |
Wait a second, I think the above error may be related to the response back from trpc being different than that of the call signature: This is returned: [
{
"result": {
"data": [
{
"accountId": "538704730908"
}
]
}
}
] Whereas I expected: [
{
"accountId": "12314"
}
] |
That's done the trick. Will write up a helper function in the morning and provide the solution here |
@michealroberts Interesting, I can't see anything in the diff between 10.41.0 and 10.42.0 of trpc which would suggest this to be resolved. But I'll try updating later today and see if I get the same 😄 |
Upon upgrading from Node 16 to Node 18, i started to get a related error in my tests:
The fix was to change the tRPC endpoint in my tRPC client for my react web application from: const url = '/api/trpc' to const url = `${window.location.protocol}//${window.location.host}/api/trpc` Which should basically be the same thing anyway. |
Is this resolved for you guys? |
@maloguertin Yeh for me, this has been resolved, although ... looking at the API for msw version 2, we might need to expose some extras for forward and backward compatibility. |
Describe the bug
So since upgrading to the latest trpc version, it seems that this library fails, although I believe the issue is not with the library per se.
To Reproduce
Install tRPC: v10.34.0 or higher
Setup tropic-msw
See error being thrown ...
Expected behavior
Prior to this, version 10.32.0 of @trpc/* packages worked well with msw-trpc, with no issue. However, since upgrading @trpc to the latest versions ^10.34 I have seen this error.
Versions
typescript: v5.1.3
tRPC: v10.36.0
msw: v1.2.3
The text was updated successfully, but these errors were encountered: