You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've used [email protected] to scaffold a project and am trying to expose certain tRPC procedures externally (so that they can be invoked via Vercel Cron jobs).
import{typeNextApiRequest,typeNextApiResponse}from"next";import{appRouter,createCaller}from"../../../server/api/root";import{createTRPCContext}from"../../../server/api/trpc";constuserByIdHandler=async(req: NextApiRequest,res: NextApiResponse)=>{// Create context and callerconstctx=awaitcreateTRPCContext({ req, res });constcaller=createCaller(ctx);try{const{ id }=req.query;constuser=awaitcaller.user.getById(id);res.status(200).json(user);}catch(cause){if(causeinstanceofTRPCError){// An error from tRPC occurredconsthttpCode=getHTTPStatusCodeFromError(cause);returnres.status(httpCode).json(cause);}// Another error occurredconsole.error(cause);res.status(500).json({message: "Internal server error"});}};exportdefaultuserByIdHandler;
I get 13 TypeScript errors, most significantly:
Module '"../../../server/api/root"' has no exported member 'createCaller'. on line 2, col 21
For this I have confirmed that the path points to src/server/api/root.ts
I have not modified src/server/api/root.ts from the original version and it looks like this - there is indeed no createCaller export:
import{postRouter}from"~/server/api/routers/post";import{createTRPCRouter}from"~/server/api/trpc";/*** This is the primary router for your server.** All routers added in /api/routers should be manually added here.*/exportconstappRouter=createTRPCRouter({post: postRouter,});// export type definition of APIexporttypeAppRouter=typeofappRouter;
Object literal may only specify known properties, and 'req' does not exist in type '{ headers: Headers; }'. on line 7, col 41
Cannot find name 'TRPCError'. Did you mean 'RTCError'? on line 14, col 26
This is fixed by importing the error type:
import{TRPCError}from'@trpc/server';
Cannot find name 'getHTTPStatusCodeFromError'. on line 16, col 24
Since I've only ever used the Next.js App Router and not the pages router, as a troubleshooting step I've tried scaffolding a new project using pages router, but that also has the same issues.
I've also pored over #1709, #1721, and c603e65 many times trying to figure out where createCaller() is and createCallerFactory() is implemented.
I'm not familiar with the internals of create-t3-app or tRPC well enough to know whether this is just a documentation issue, or if there's actually something missing from the create-t3-app template which is intended to be there.
The text was updated successfully, but these errors were encountered:
a1031
changed the title
bug: Problems using example in docs for exposing procedures externally
bug: Problems using example in docs for exposing tRPC procedures externally
Feb 2, 2024
Provide environment information
System:
OS: macOS 14.2.1
CPU: (8) arm64 Apple M2
Memory: 97.97 MB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
Yarn: 1.22.21 - /opt/homebrew/bin/yarn
npm: 10.2.5 - ~/.nvm/versions/node/v20.10.0/bin/npm
ct3aMetadata.initVersion
:7.26.0
Next.js:
14.1.0
(using App Router)Describe the bug
I've used
[email protected]
to scaffold a project and am trying to expose certain tRPC procedures externally (so that they can be invoked via Vercel Cron jobs).Based on the Expose a single procedure externally example, when I create a file called
src/app/api/test/[id].ts
and include this:I get 13 TypeScript errors, most significantly:
Module '"../../../server/api/root"' has no exported member 'createCaller'.
on line 2, col 21src/server/api/root.ts
src/server/api/root.ts
from the original version and it looks like this - there is indeed nocreateCaller
export:Object literal may only specify known properties, and 'req' does not exist in type '{ headers: Headers; }'.
on line 7, col 41Cannot find name 'TRPCError'. Did you mean 'RTCError'?
on line 14, col 26Cannot find name 'getHTTPStatusCodeFromError'.
on line 16, col 24Since I've only ever used the Next.js App Router and not the pages router, as a troubleshooting step I've tried scaffolding a new project using pages router, but that also has the same issues.
I've also pored over #1709, #1721, and c603e65 many times trying to figure out where
createCaller()
is andcreateCallerFactory()
is implemented.Reproduction repo
https://codesandbox.io/p/devbox/mn5qf3?file=%2Ftest%2Fsrc%2Fapp%2Fapi%2Ftest%2F%5Bid%5D.ts%3A3%2C10
To reproduce
test/src/app/api/test/[id].ts
file in the CodeSandbox devbox.Additional information
I'm not familiar with the internals of
create-t3-app
or tRPC well enough to know whether this is just a documentation issue, or if there's actually something missing from thecreate-t3-app
template which is intended to be there.The text was updated successfully, but these errors were encountered: