tRPCttRPC
Powered by
KyleBK
tRPC•14mo ago•
5 replies
KyleB

can't create context when using nextjs app dir

Im trying to use the latest version of nextjs and make use of the app directory. when trying to make a create context function like they show in the docs here: https://trpc.io/docs/server/context , it gives the following error when i try to create the handler on the frontend
Types of parameters 'opts' and 'opts' are incompatible.
    Property 'res' is missing in type 'FetchCreateContextFnOptions' but required in type 'CreateNextContextOptions'
Types of parameters 'opts' and 'opts' are incompatible.
    Property 'res' is missing in type 'FetchCreateContextFnOptions' but required in type 'CreateNextContextOptions'

I even try using
createNextApiHandler
createNextApiHandler
which removes the error from here but causes issues when trying to create the trpc/server.ts file for the server components, particularly when trying to use the
createCallerFactory
createCallerFactory
function (see second screenshot)
Type '(opts: CreateNextContextOptions) => {}' is not assignable to type '() => MaybePromise<{}>'.
Target signature provides too few arguments. Expected 1 or more, but got 0.
Type '(opts: CreateNextContextOptions) => {}' is not assignable to type '() => MaybePromise<{}>'.
Target signature provides too few arguments. Expected 1 or more, but got 0.

any help would be apprieciated
Screenshot_2025-01-03_at_7.42.52_PM.png
Context | tRPC
Your context holds data that all of your tRPC procedures will have access to, and is a great place to put things like database connections or authentication information.
Context | tRPC
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

trpc with app dir nextjs
MajMMaj / ❓-help
3y ago
SSR with NextJs app directory
WiznetWWiznet / ❓-help
14mo ago
tRPC context and NextJS
MonkeyStructMMonkeyStruct / ❓-help
4y ago
Nextjs App Router example repo doesn't match NextJS App Router Docs
BastinBBastin / ❓-help
14mo ago