Evan
Evan14mo ago

TRPC type checking during build fails

Environment: node 18.6.0, yarn Whats wrong: Type checking at build time fails. . I think this might be an issue with the Lambda Adapter These scripts are run. deploying through AWS amplify. this doesn't error locally $ yarn run typecheck $ yarn run build client scripts
"scripts": {
"start": "vite",
"build": "vite build",
"serve": "vite preview",
"typecheck": "tsc --noEmit"
},
"scripts": {
"start": "vite",
"build": "vite build",
"serve": "vite preview",
"typecheck": "tsc --noEmit"
},
client trpc
import { createTRPCReact, inferReactQueryProcedureOptions } from "@trpc/react-query";
import { inferRouterInputs, inferRouterOutputs } from "@trpc/server";
import { type AppRouter } from "server"

export const trpc = createTRPCReact<AppRouter>(); // <---- TSC FAILS HERE
import { createTRPCReact, inferReactQueryProcedureOptions } from "@trpc/react-query";
import { inferRouterInputs, inferRouterOutputs } from "@trpc/server";
import { type AppRouter } from "server"

export const trpc = createTRPCReact<AppRouter>(); // <---- TSC FAILS HERE
server trpc
import { inferAsyncReturnType, initTRPC } from "@trpc/server";
import { CreateAWSLambdaContextOptions } from "@trpc/server/adapters/aws-lambda";
import { APIGatewayProxyEventV2 } from "aws-lambda/trigger/api-gateway-proxy";

export const createContext = ({
event,
context,
}: CreateAWSLambdaContextOptions<APIGatewayProxyEventV2>) => ({
event: event,
apiVersion: (event as { version?: string }).version || "1.0",
user: event.headers["x-user"],
});

type Context = inferAsyncReturnType<typeof createContext>;
const t = initTRPC.context<Context>().create();
...
import { inferAsyncReturnType, initTRPC } from "@trpc/server";
import { CreateAWSLambdaContextOptions } from "@trpc/server/adapters/aws-lambda";
import { APIGatewayProxyEventV2 } from "aws-lambda/trigger/api-gateway-proxy";

export const createContext = ({
event,
context,
}: CreateAWSLambdaContextOptions<APIGatewayProxyEventV2>) => ({
event: event,
apiVersion: (event as { version?: string }).version || "1.0",
user: event.headers["x-user"],
});

type Context = inferAsyncReturnType<typeof createContext>;
const t = initTRPC.context<Context>().create();
...
router
import { publicProcedure, router } from "../utils/trpc";
export type AppRouter = typeof appRouter

export const appRouter = router({
hello: publicProcedure.query(() => "Hello World!"),
});
import { publicProcedure, router } from "../utils/trpc";
export type AppRouter = typeof appRouter

export const appRouter = router({
hello: publicProcedure.query(() => "Hello World!"),
});
error traceback attached
2 Replies
Nick
Nick14mo ago
Make sure all your trpc versions are the same
Evan
Evan14mo ago
Everything is on the latest version