// functions/.../index.tsconst trpcHandler = awsLambdaRequestHandler({ router: appRouter, createContext: createTrpcContext,});export const handler: APIGatewayProxyHandlerV2 = async (event, context) => { if (event.rawPath.startsWith("/trpc")) { event.rawPath = event.rawPath.slice(5); if (event.rawPath === "") { event.rawPath = "/"; } } if (event.requestContext?.http?.path) { event.requestContext.http.path = event.rawPath; } return trpcHandler(event, context);};
awsLambdaRequestHandler
@trpc/server/adapters/aws-lambda
// functions/.../index.tsexport const handler = awsLambdaRequestHandler({ router: appRouter, createContext: createTrpcContext,});
// sst.config.tsexport const trpc = new sst.aws.Function("Api", { handler: "packages/functions/src/api/index.handler", runtime: "nodejs20.x", memory: "128 MB", link: [database, auth], url: true,});export const apiRouter = new sst.aws.Router("ApiRouter", { domain: { name: "api." + domain, dns: sst.cloudflare.dns(), }, routes: { "/trpc/*": trpc.url, },});
server/src/utils/trpc.ts
import { initTRPC } from "@trpc/server";export const t = initTRPC.create()`
server/src/app.ts
import { t } from "~/utils/trpc" // this causes the errorimport { t } from "./utils/trpc" // this has resolved it
// ... "paths": { "~/*": ["./src/*"] }
createTRPCQueryUtils