functiondjF
tRPC3y ago
17 replies
functiondj

404 TRPCError: no query procedure on path

Hi, this is my entire standalone tRPC server:
import { initTRPC } from "@trpc/server";
import { createHTTPServer } from "@trpc/server/adapters/standalone";
import cors from "cors";

const t = initTRPC.create();
const appRouter = t.router({
    foo: t.procedure.query(() => "hi"),
});

const server = createHTTPServer({
    middleware: cors(),
    router: appRouter,
});

export type AppRouter = typeof appRouter;

server.listen(3000);

and here is my tRPC client:
const trpcClient = trpc.createClient({
    links: [
        httpBatchLink({
            url: "http://localhost:3000/trpc"
        }),
    ],
});

but when i use it with trpc.foo.useQuery(), this the response:
{
    "error": {
        "message": "No \"query\"-procedure on path \"trpc/foo\"",
        "code": -32004,
        "data": {
            "code": "NOT_FOUND",
            "httpStatus": 404,
            "stack": "TRPCError: No \"query\"-procedure on path \"trpc/foo\"\n    at new TRPCError (/somepath/node_modules/@trpc/server/dist/TRPCError-6a1653a4.mjs:52:12)\n    at callProcedure
                  [...]
        }
    }
}


What am i doing wrong? I already tried removing /trpc from the url that the client uses which also resulted in 404.
Was this page helpful?