Zod v4 Issues with inferred typeof appRouter
Here is the full error message:
src/routers/_app.ts:13:14 - error TS2742: The inferred type of 'appRouter' cannot be named without a reference to '../../node_modules/zod/v4/core/util.cjs'. This is likely not portable. A type annotation is necessary.
- I am in a turborepo with a separate frontend and backend apps.
- I use tRPC as a package so both back and frontend can have access
- I use Zod v4 and have made use of pnpm catalog: in order to keep version consistent across all apps and packages
- my db (ORM using Drizzle) is in its own 'db' package again to help with access on both front and back apps
- my tRPC context contains db (drizzle), clerk auth context, and the clerk JS client
I don't really understand the issue completely and there's not very much online on this? But it seems to happen a lot in my codebases and I am never sure what I have done to cause it
3 Replies
This is an annoying error that I’ve seen quite a lot where you’re trying to re-export a type which depends on another package. The cheap fix is typically to just import the package (zod) into the file with the error like
import “zod”
It happens most often when a package has a core package which isn’t installed directly but it can rarely happen in your situation too
so I actually finally found the issue and to be honest because I don't fully understand TS I am not sure why it solved it here because I spun up a T3-Turbo repo and used the exact same configs and suddenly no error BUT I made sure in tsconfig.json:
That makes sense, I'm not totally clued up on this issue but I have heard of declarations being a solution