tRPCを使ったモノレポプロジェクトの動作がおかしい
ServerComponentから呼び出すとServerプロジェクト側のPrismaを呼び出そうとする
現段階のソースコードを上げました
clientとserverプロジェクトでtRPC・Prismaを使ったプロジェクトを作ろうとしたが、client側からtRPCを呼び出すと何故かserver側のprismaを使おうとしてしまう。
また、同時に.envも勝手に参照しようとしてエラーを吐く
発生している問題・エラー
Error:
Invalid `prisma.post.findMany()` invocation:
Prisma Client could not locate the Query Engine for runtime "windows".
This is likely caused by a bundler that has not copied "query_engine-windows.dll.node" next to the resulting bundle.
Ensure that "query_engine-windows.dll.node" has been copied next to the bundle or in "node_modules\.pnpm\@prisma+client@5.20.0_prisma@5.20.0\node_modules\.prisma\client".
We would appreciate if you could take the time to share some information with us.
Please help us by answering a few questions: https://pris.ly/engine-not-found-bundler-investigation
The following locations have been searched:
E:\node\tickets\client\node_modules\.pnpm\@prisma+client@5.20.0_prisma@5.20.0\node_modules\.prisma\client
E:\node\tickets\client\.next\server
E:\node\tickets\server\node_modules\.pnpm\@prisma+client@5.20.0_prisma@5.20.0\node_modules\@prisma\client
E:\node\tickets\client\.prisma\client
/tmp/prisma-engines
該当するソースコード
/client/src/app/_trpc/server.ts
import "server-only";
import { createHydrationHelpers } from "@trpc/react-query/rsc";
import { headers } from "next/headers";
import { cache } from "react";
import { createCaller, AppRouter } from "@/../../server/src/routes/root";
import { createTRPCContext } from "@/../../server/src/trpc";
import { createQueryClient } from "./query-client";
const createContext = cache(() => {
const heads = new Headers(headers())
heads.set("x-trpc-source", "rsc")
return createTRPCContext({
headers: heads
})
});
const getQueryClient = cache(createQueryClient)
const caller = createCaller(createContext)
export const { trpc: api, HydrateClient } = createHydrationHelpers<AppRouter>(
caller,
getQueryClient
)
/client/src/app/page.tsx
import { api } from "@/app/_trpc/server";
export default async function Home() {
const allPosts = await api.posts.getAllPosts()
return (
<>
</>
);
}
自分で試したこと
キャッシュの削除・T3-Stackとの見比べ等
0