Comments (10)
Hi @maloguertin ... could we brainstorm some solutions to this issue please 🙏
from msw-trpc.
That's done the trick. Will write up a helper function in the morning and provide the solution here
from msw-trpc.
@alex-way Weirdly, today updating to al of the latest versions - the error has passed. So @trpc version 10.42.0 seems to be the version to aim for?
from msw-trpc.
@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 😄
from msw-trpc.
Upon upgrading from Node 16 to Node 18, i started to get a related error in my tests:
TRPCClientError: Failed to parse URL from /api/trpc/projectRoles.all
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.
from msw-trpc.
Hi @maloguertin ... could we brainstorm some solutions to this issue please 🙏
Hey there! You found any solution for this issue?
from msw-trpc.
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. http://testhost.local/api/trpc
and then use the same value in your MSW mocks:
// 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:
RPCClientError: Missing result
at Function.from (file:///C:/code/cloud-management-platform-2/src/cmp-web-ui/node_modules/@trpc/client/dist/TRPCClientError-0de4d231.mjs:37:16)
at file:///C:/code/cloud-management-platform-2/src/cmp-web-ui/node_modules/@trpc/client/dist/httpBatchLink-204206a5.mjs:200:56
at runNextTicks (node:internal/process/task_queues:60:5)
at listOnTimeout (node:internal/timers:540:9)
at processTimers (node:internal/timers:514:7) {
meta: undefined,
shape: undefined,
data: undefined,
[cause]: Error: Missing result
at file:///C:/code/cloud-management-platform-2/src/cmp-web-ui/node_modules/@trpc/client/dist/httpBatchLink-204206a5.mjs:88:35
at runNextTicks (node:internal/process/task_queues:60:5)
at listOnTimeout (node:internal/timers:540:9)
at processTimers (node:internal/timers:514:7)
}
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.
from msw-trpc.
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"
}
]
from msw-trpc.
Is this resolved for you guys?
from msw-trpc.
@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.
from msw-trpc.
Related Issues (20)
- Serialization of request input with e.g., superjson HOT 5
- Support for createTRPCReact (react query) HOT 2
- Integrate with ladle HOT 1
- Is it possible to reproduce the case where the server side throws a TRPCError? HOT 6
- Call to GET http://127.0.0.1:49475/ not handled HOT 1
- Cannot run msw-trpc with vitest HOT 4
- `req.getInput()` should indicate that its return type is a promise for mutations HOT 2
- Support tRPC subscriptions (WebSockets) HOT 1
- trpc query firing before service worker is started HOT 2
- When output parser is used in the procedure, `ctx.data` argument type is unknown (invalid type) HOT 1
- Request: Example integration with Next and RTL
- `req.getInput` incorrectly typed for `query` HOT 2
- Compatibility with msw 2.0
- Issue running with react hooks with tRPC 10.33.1+ HOT 3
- Merged routes not working with latest trpc and msw-trpc HOT 2
- Issues throwing errors in 2.0.0-beta.0 HOT 1
- Cannot trigger useQuery `error` or `isError` response in test HOT 2
- Support for V11 HOT 4
- Bug: `output` is used inside `getMutationInput`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msw-trpc.