\n\n### Link to reproduction\n\nhttps://github.com/brandongit2/trpc-tanstack-router-bug-repro/blob/main/index.ts\n\n### To reproduce\n\n1. Clone the repro repo\n2. `pnpm install`\n3. Open `index.ts`\n4. Type error:\n ```ts\n Type 'QueryClient' is not assignable to type 'QueryClient | (() => QueryClient)'.\n Type 'import(\"/Users/brandontsang/projects/trpc-tanstack-router-bug-repro/node_modules/.pnpm/@tanstack+query-core@5.66.4/node_modules/@tanstack/query-core/build/modern/hydration-k2LfsAVL\", { with: { \"resolution-mode\": \"import\" } }).b' is not assignable to type 'import(\"/Users/brandontsang/projects/trpc-tanstack-router-bug-repro/node_modules/.pnpm/@tanstack+query-core@5.66.4/node_modules/@tanstack/query-core/build/modern/hydration-BHYO6Wdv\").b'.\n Property '#private' in type 'QueryClient' refers to a different member that cannot be accessed from within type 'QueryClient'.\n ```\n\n### Additional information\n\nThis comes from the fact that `@trpc/tanstack-react-query` doesn't have dedicated ESM type exports.\n\n- In my repro, I have:\n - `\"type\": \"module\"` in `package.json`\n - `\"moduleResolution\": \"nodenext\"` in my `tsconfig.json`\n- When I import from `@tanstack/react-query`, the `.d.ts` files are interpereted as ESM by TypeScript, since they have dedicated ESM type declarations:\n - \u003Cimg width=\"300\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/02697f38-cd10-45ba-b0e3-380b3a7cf568\" />\n- But when I import from `@trpc/tanstack-react-query`, the `.d.ts` files are interpereted as CJS by TypeScript, since the `package.json` doesn't specify `\"type\"`.\n- When `@trpc/tanstack-react-query`'s types import `@tanstack/react-query`, they come in as CJS types. `@tanstack/react-query`'s ESM and CJS types don't seem to be compatible with one another.\n\nIt could be argued that this is also a TanStack Query bug, since their ESM and CJS types ought to be compatible with one another anyway.\n\n---\n\n### Workarounds/fixes:\n\n1. Patch `@trpc/tanstack-react-query` to force ESM imports:\n - Find the `.d.ts` file that imports `@tanstack/react-query` (in this repro's case, it's `@trpc/tanstack-react-query/dist/internals/createOptionsProxy.d.ts`)\n - add an import attribute: `...from '@tanstack/react-query' with {'resolution-mode': 'import'}`\n - Type error gone!\n2. Or, in the user's project, import `@tanstack/react-query` as CJS and override the type:\n - \u003Cimg width=\"951\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/2bc65705-b4b9-45bd-bdf7-6213bebedee2\" />\n - Type error gone!\n\n### 👨👧👦 Contributing\n\n- [ ] 🙋♂️ Yes, I'd be down to file a PR fixing this bug!",[2892,2895],{"name":2893,"color":2894},"🐛 bug","d73a4a",{"name":2896,"color":2872},"🙋♂️ help wanted",6554,"bug: Type incompatibility between `@trpc/tanstack-react-query` and `@tanstack/react-query`","2025-03-01T23:59:14Z","https://github.com/trpc/trpc/issues/6554",0.7040791,{"description":2903,"labels":2904,"number":2908,"owner":2874,"repository":2874,"state":2876,"title":2909,"updated_at":2910,"url":2911,"score":2912},"### Provide environment information\n\n``` \nSystem:\n OS: macOS 14.5\n CPU: (12) arm64 Apple M2 Max\n Memory: 73.41 MB / 32.00 GB\n Shell: 5.9 - /bin/zsh\n Binaries:\n Node: 20.18.0 - ~/.nvm/versions/node/v20.18.0/bin/node\n Yarn: 1.22.22 - ~/Library/pnpm/yarn\n npm: 10.8.2 - ~/.nvm/versions/node/v20.18.0/bin/npm\n Browsers:\n Chrome: 135.0.7049.117\n Edge: 134.0.3124.62\n Safari: 17.5\n npmPackages:\n @trpc/server: ^11.1.2 => 11.1.2 \n typescript: ^5.8.3 => 5.8.3 \n```\n\n### Describe the bug\n\nWhen using the documented pattern for defining a router (verbatim from https://trpc.io/docs/server/routers), TypeScript emits declaration files that include imports from `@trpc/server/dist/unstable-core-do-not-import`, which is not exposed via the package’s exports field.\n\nThis makes the generated `.d.ts` files invalid for consumers that rely on strict ESM resolution, including build tools and downstream libraries.\n\n### Link to reproduction\n\nhttps://github.com/extradosages/trpc-type-leak-demo\n\n### To reproduce\n\nUse the following `trpc.ts` and `router.ts` files (copied verbatim from the docs):\n\n`trcp.ts`\n```ts\nimport { initTRPC } from '@trpc/server';\nconst t = initTRPC.create();\nexport const router = t.router;\nexport const publicProcedure = t.procedure;\n```\n\n`router.ts`\n```ts\nimport { publicProcedure, router } from './trpc';\nconst appRouter = router({\n greeting: publicProcedure.query(() => 'hello tRPC v10!'),\n});\nexport type AppRouter = typeof appRouter;\n```\n\nRun:\n```bash\ntsc --emitDeclarationOnly\n```\n\nObserve that `router.d.ts` includes:\n```ts\ndeclare const appRouter: import(\"@trpc/server/dist/unstable-core-do-not-import\").BuiltRouter\u003C...>;\n```\n\nCompare to the `package.json` `exports` field:\n```json\n\"exports\": {\n \".\": {\n \"import\": \"./dist/index.mjs\",\n ...\n },\n ...\n \"./unstable-core-do-not-import\": {\n \"import\": \"./dist/unstable-core-do-not-import.mjs\",\n ...\n }\n}\n```\n\n### Additional information\n\nMight be solved by https://github.com/trpc/trpc/issues/5004.\n\nCurrently running a workaround in production with the following patch:\n```diff\ndiff --git a/package.json b/package.json\nindex 1f03d01bd1148bffc1434ac66f9feb52ba654bc3..f73cdbd446c2421a377af8ce0459288e1ee1162b 100644\n--- a/package.json\n+++ b/package.json\n@@ -73,6 +73,11 @@\n \"require\": \"./dist/adapters/ws.js\",\n \"default\": \"./dist/adapters/ws.js\"\n },\n+ \"./dist/*\": {\n+ \"import\": \"./dist/*\",\n+ \"require\": \"./dist/*\",\n+ \"default\": \"./dist/*\"\n+ },\n \"./http\": {\n \"import\": \"./dist/http.mjs\",\n \"require\": \"./dist/http.js\",\n```\n\n### 👨👧👦 Contributing\n\n- [ ] 🙋♂️ Yes, I'd be down to file a PR fixing this bug!",[2905],{"name":2906,"color":2907},"🐛 bug: unconfirmed","e99695",6753,"bug: generated `.d.ts` files leaking un-exported types","2025-05-07T23:42:57Z","https://github.com/trpc/trpc/issues/6753",0.7065273,{"description":2914,"labels":2915,"number":2916,"owner":2874,"repository":2874,"state":2917,"title":2918,"updated_at":2919,"url":2920,"score":2921},"Getting an error when compiling a project that uses trpc, here's the error, deps and tsconfig.json\r\n\r\n### Error\r\n```\r\n../../node_modules/@trpc/server/dist/declarations/src/TRPCError.d.ts(7,14): error TS2416: Property 'cause' in type 'TRPCError' is not assignable to the same property in base type 'Error'.\r\n#22 12.52 Type 'unknown' is not assignable to type 'Error | undefined'.\r\n``` \r\n\r\n### relevant deps\r\n```\r\n\"dependencies\": {\r\n \"@trpc/server\": \"^9.22.0\"\r\n },\r\n \"devDependencies\": {\r\n \"@types/node\": \"17.0.23\",\r\n \"typescript\": \"4.6.3\"\r\n }\r\n```\r\n\r\n### tsconfig\r\n```\r\n{\r\n \"compilerOptions\": {\r\n \"target\": \"esnext\",\r\n \"allowJs\": true,\r\n \"strict\": true,\r\n \"strictNullChecks\": true,\r\n \"forceConsistentCasingInFileNames\": true,\r\n \"esModuleInterop\": false,\r\n \"allowSyntheticDefaultImports\": true,\r\n \"moduleResolution\": \"node\",\r\n \"module\": \"CommonJS\",\r\n \"resolveJsonModule\": true,\r\n \"incremental\": true\r\n },\r\n \"include\": [\"**/*.ts\", \"**/*.d.ts\", \"**/*.tsx\"],\r\n \"exclude\": [\"node_modules\"]\r\n}\r\n```",[],1927,"closed","Error compiling trpc: TRPCError.d.ts(7,14): error TS2416","2022-10-04T12:02:52Z","https://github.com/trpc/trpc/issues/1927",0.655938,{"description":2923,"labels":2924,"number":2926,"owner":2874,"repository":2874,"state":2917,"title":2927,"updated_at":2919,"url":2928,"score":2929},"Hi there,\r\n\r\nfirst of all: Thanks a lot for creating trpc :) I just recently stumpled upon it and I'm quite enthusiastic about it's design.\r\n\r\nNow to the problem:\r\n\r\nI'm trying to use trpc in a pnpm-driven monorepo. When I try to compile the package that's using trpc (both `@trpc/server` and `@trpc/client`), `tsc` fails with:\r\n\r\n```\r\n../../../../node_modules/.pnpm/@trpc+server@9.23.4/node_modules/@trpc/server/dist/declarations/src/adapters/node-http/types.d.ts:3:16 - error TS2307: Cannot find module 'qs' or its corresponding type declarations.\r\n\r\n3 import qs from 'qs';\r\n\r\n[...]\r\n\r\n../../../../node_modules/.pnpm/@trpc+server@9.23.4/node_modules/@trpc/server/dist/declarations/src/adapters/standalone.d.ts:5:107 - error TS2344: Type 'IncomingMessage' does not satisfy the constraint 'NodeHTTPRequest'.\r\n Type 'IncomingMessage' is not assignable to type '{ method?: string; query?: any; body?: unknown; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.\r\n Types of property 'method' are incompatible.\r\n Type 'string | undefined' is not assignable to type 'string'.\r\n Type 'undefined' is not assignable to type 'string'.\r\n\r\n5 export declare type CreateHTTPHandlerOptions\u003CTRouter extends AnyRouter> = NodeHTTPHandlerOptions\u003CTRouter, http.IncomingMessage, http.ServerResponse>;\r\n```\r\n\r\nThe first one\r\n```\r\nTS2307: Cannot find module 'qs' or its corresponding type declarations.\r\n```\r\n\r\ncan be fixed by installing `@types/qs`. However, I don't think that should be necessary.\r\n\r\nThe second one\r\n```\r\nTS2344: Type 'IncomingMessage' does not satisfy the constraint 'NodeHTTPRequest'.\r\n```\r\nisn't explicable to me but at least resembles one of the errors documented in #1022.\r\n\r\nThis issue was closed by #1151, which should be included with the trpc version I'm using (9.23.4).\r\n\r\nIt's possible that this is related to my use of pnpm.\r\n\r\nAny hint would be appreciated :) I'll keep you posted, if I find anything myself.",[2925],{"name":2893,"color":2894},1904,"Type Errors","https://github.com/trpc/trpc/issues/1904",0.66271925,{"description":2931,"labels":2932,"number":2933,"owner":2874,"repository":2874,"state":2917,"title":2934,"updated_at":2935,"url":2936,"score":2937},"Hi @KATT, \r\nThank you for this great library. \r\n\r\nI am reporting that the server types need updates after the latest typescript release (4.6): \r\n\r\n```bash\r\nnode_modules/@trpc/server/dist/declarations/src/TRPCError.d.ts:7:14 - error TS2416: Property 'cause' in type 'TRPCError' is not assignable to the same property in base type 'Error'.\r\n Type 'unknown' is not assignable to type 'Error | undefined'.\r\n\r\n7 readonly cause?: unknown;\r\n ~~~~~\r\n\r\n\r\nFound 1 error in node_modules/@trpc/server/dist/declarations/src/TRPCError.d.ts:7\r\n```\r\n\r\n\r\n\r\nBest regards \r\n",[],1588,"Type error in @trpc/server with TS 4.6","2022-10-04T12:03:04Z","https://github.com/trpc/trpc/issues/1588",0.6729942,{"description":2939,"labels":2940,"number":2950,"owner":2874,"repository":2874,"state":2917,"title":2951,"updated_at":2952,"url":2953,"score":2954},"While working on a project with tRPC (based on the `fastify-server` example), I came across a type error while attempting to build the project.\r\n```\r\nnode_modules/@trpc/client/dist/declarations/src/TRPCClientError.d.ts:13:14 - error TS2416: Property 'cause' in type 'TRPCClientError\u003CTRouter>' is not assignable to the same property in base type 'Error'.\r\n Type 'Maybe\u003CError>' is not assignable to type 'Error | undefined'.\r\n Type 'null' is not assignable to type 'Error | undefined'.\r\n\r\n13 readonly cause: Maybe\u003CError>;\r\n ~~~~~\r\n\r\nnode_modules/@trpc/server/dist/declarations/src/TRPCError.d.ts:7:14 - error TS2416: Property 'cause' in type 'TRPCError' is not assignable to the same property in base type 'Error'.\r\n Type 'unknown' is not assignable to type 'Error | undefined'.\r\n\r\n7 readonly cause?: unknown;\r\n ~~~~~\r\n``` \r\n \r\nI managed to figure out what causes the bug: There is a breaking change in `typescript@4.6.2`, [this one](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-6.html#object-rests-drop-unspreadable-members-from-generic-objects) I believe \r\nThrough more testing, I also figured out a few workarounds: \r\n- Use `typescript@4.5.5`\r\n- Set the `target` in `tsconfig.json` to `ES2021`\r\n- Set the `target` in `tsconfig.json` to `ES6` \r\n \r\nI was going to file a PR, but then I wasn't sure exactly what needs to be fixed(?). Is this a bug that needs fixing within tRPC itself? Should there be a warning in the docs? Should the examples use the aforementioned `tsconfig` workaround? Should the entire repo use the `tsconfig` workaround? \r\n \r\nI am very willing to help with a fix but I need some insight. ",[2941,2944,2947],{"name":2942,"color":2943},"@trpc/server","9BE78E",{"name":2945,"color":2946},"@trpc/client","6095C2",{"name":2948,"color":2949},"🔎 needs more investigation/info","d4c5f9",2292,"Potential for future type error in TRPCError & TRPCClientError","2022-09-29T21:24:11Z","https://github.com/trpc/trpc/issues/2292",0.68547,{"description":2956,"labels":2957,"number":2958,"owner":2874,"repository":2874,"state":2917,"title":2959,"updated_at":2960,"url":2961,"score":2962},"We are still seeing this issue https://github.com/trpc/trpc/issues/2292:\r\n\r\n```\r\nnode_modules/@trpc/client/src/TRPCClientError.ts:18:19 - error TS2416: Property 'cause' in type 'TRPCClientError\u003CTRouter>' is not assignable to the same property in base type 'Error'.\r\n Type 'Maybe\u003CError>' is not assignable to type 'Error | undefined'.\r\n Type 'null' is not assignable to type 'Error | undefined'.\r\n\r\n18 public readonly cause;\r\n```\r\n\r\nWith the following deps:\r\n\r\n```\r\n \"typescript\": \"4.8.4\",\r\n \"@trpc/client\": \"9.27.2\",\r\n \"@trpc/react\": \"9.27.2\",\r\n \"@trpc/server\": \"9.27.2\",\r\n```\r\n\r\n_Originally posted by @moltar in https://github.com/trpc/trpc/issues/2292#issuecomment-1262366016_\r\n ",[],2851,"Type error with TRPCError & TRPCClientError","2022-10-14T06:21:43Z","https://github.com/trpc/trpc/issues/2851",0.68770814,{"description":2964,"labels":2965,"number":2966,"owner":2874,"repository":2874,"state":2917,"title":2967,"updated_at":2968,"url":2969,"score":2970},"First of all, thank you **so** much for building trpc, I'm finding it incredibly productive to work with.\r\n\r\nI have a monorepo (Yarn V3 with PnP) with express+trpc server and react+trpc client. When building (running `tsc` in the client), I get the following errors:\r\n\r\n```bash\r\n$ yarn tsc\r\n../../.yarn/__virtual__/@trpc-react-virtual-ad6238a3af/0/cache/@trpc-react-npm-9.8.1-katt-issue-1020-pin-2021-09-27-12-36-16.6-6f182fd388-e6c7db2e9e.zip/node_modules/@trpc/react/dist/declarations/src/createReactQueryHooks.d.ts:30:70 - error TS2307: Cannot find module 'packages/client/src/internals/TRPCClient' or its corresponding type declarations.\r\n\r\n30 createClient: (opts: CreateTRPCClientOptions\u003CTRouter>) => import(\"packages/client/src/internals/TRPCClient\").TRPCClient\u003CTRouter>;\r\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\n../../.yarn/__virtual__/objection-virtual-f49c97575b/0/cache/objection-npm-3.0.0-alpha.4-8ca0cd8297-eec790bc78.zip/node_modules/objection/typings/objection/index.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.\r\n\r\n1 /// \u003Creference types=\"node\" />\r\n ~~~~\r\n\r\n../../.yarn/cache/@trpc-server-npm-9.8.1-katt-issue-1020-pin-2021-09-27-12-36-16.6-cdb5a7a4be-e62c21a45b.zip/node_modules/@trpc/server/dist/declarations/src/adapters/node-http/types.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.\r\n\r\n1 /// \u003Creference types=\"node\" />\r\n ~~~~\r\n\r\n../../.yarn/cache/@trpc-server-npm-9.8.1-katt-issue-1020-pin-2021-09-27-12-36-16.6-cdb5a7a4be-e62c21a45b.zip/node_modules/@trpc/server/dist/declarations/src/adapters/node-http/types.d.ts:3:16 - error TS2307: Cannot find module 'qs' or its corresponding type declarations.\r\n\r\n3 import qs from 'qs';\r\n ~~~~\r\n\r\n../../.yarn/cache/@trpc-server-npm-9.8.1-katt-issue-1020-pin-2021-09-27-12-36-16.6-cdb5a7a4be-e62c21a45b.zip/node_modules/@trpc/server/dist/declarations/src/adapters/standalone.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.\r\n\r\n1 /// \u003Creference types=\"node\" />\r\n ~~~~\r\n\r\n../../.yarn/cache/@trpc-server-npm-9.8.1-katt-issue-1020-pin-2021-09-27-12-36-16.6-cdb5a7a4be-e62c21a45b.zip/node_modules/@trpc/server/dist/declarations/src/adapters/standalone.d.ts:5:107 - error TS2344: Type 'IncomingMessage' does not satisfy the constraint 'NodeHTTPRequest'.\r\n Type 'IncomingMessage' is not assignable to type '{ method?: string; query?: any; body?: unknown; }'.\r\n Types of property 'method' are incompatible.\r\n Type 'string | undefined' is not assignable to type 'string'.\r\n Type 'undefined' is not assignable to type 'string'.\r\n\r\n5 export declare type CreateHTTPHandlerOptions\u003CTRouter extends AnyRouter> = NodeHTTPHandlerOptions\u003CTRouter, http.IncomingMessage, http.ServerResponse>;\r\n ~~~~~~~~~~~~~~~~~~~~\r\n\r\n../../.yarn/cache/@trpc-server-npm-9.8.1-katt-issue-1020-pin-2021-09-27-12-36-16.6-cdb5a7a4be-e62c21a45b.zip/node_modules/@trpc/server/dist/declarations/src/http/internals/types.d.ts:1:23 - error TS2688: Cannot \r\nfind type definition file for 'node'.\r\n\r\n1 /// \u003Creference types=\"node\" />\r\n ~~~~\r\n\r\n../../.yarn/cache/@trpc-server-npm-9.8.1-katt-issue-1020-pin-2021-09-27-12-36-16.6-cdb5a7a4be-e62c21a45b.zip/node_modules/@trpc/server/dist/declarations/src/subscription.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.\r\n\r\n1 /// \u003Creference types=\"node\" />\r\n ~~~~\r\n\r\n../../.yarn/cache/tarn-npm-3.0.1-afc495be8f-c7347ce8c4.zip/node_modules/tarn/dist/Pool.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.\r\n\r\n1 /// \u003Creference types=\"node\" />\r\n ~~~~\r\n\r\n\r\nFound 9 errors.\r\n```\r\n\r\nThe one place I refer to the server from my client is in one file:\r\n\r\n```ts\r\nimport type { AppRPCRouter } from \"@ski/server/src/api/router\";\r\nimport { createReactQueryHooks } from \"@trpc/react\";\r\n\r\nexport const trpc = createReactQueryHooks\u003CAppRPCRouter>();\r\n```\r\n\r\nI'm not sure what's going on here, as it looks like typescript is trying to build (or typecheck) the server files, but then doesn't have the correct local packages to be able to do this (objection is the ORM I'm using on the server).\r\n\r\nHow would I go about fixing this?\r\n\r\nThanks!",[],1022,"Typescript errors when building","2022-10-04T18:08:08Z","https://github.com/trpc/trpc/issues/1022",0.6934752,["Reactive",2972],{},["Set"],["ShallowReactive",2975],{"$fTRc1wZytZ_XrK4EfJfei_Sz-An4H4Yy6syhVxH_PVJc":-1,"$fRmt55Ff_CoRhwKJaJKSNcwM0nVcC-RzCAl2gIHZ_nyQ":-1},"/trpc/trpc-openapi/399"]