tRPC Websockets | package subpath not defined by exports
So basically I am playing around with tRPC Websockets/Subscriptions.
I am primarily using this repo as a reference -> https://github.com/trpc/examples-next-prisma-websockets-starter
I've created a server.ts which has the following contents ->
I'm also using the dev version (wssDevServer) for my localhost, which runs without any issues. When I attempt to run this on my custom VPS (centos +
nginx), with I get the error shown in the screenshot.
Been googling for the past 1 hour, but nothing which really helps me to understand how to approach this issue?
1 Reply
Okay, so after many hours of debugging and tests, this appears to be some extremely weird issue which isn't caused by tRPC itself, but rather by tRPC websockets/subscriptions working in combination with the setup of the T3 stack. ( or im just dumb ? not impossible 😄 )
The first error which I showed in the screenshot was actually caused due to the fact that after building, the server.js file in the dist directory was trying to import adapters/ws from "dist/adapters/ws".
Went in the node_modules/@trpc/server/package.json and after examining it it doesn't indeed export any subpath "dist/adapters/ws".
After rebuilding this with and checking the files, it actually started pointing to the correct subpath and the first error got resolved.
This caused another error to start popping up, and that was caused by the env handler created by the T3 package, it was expecting to run with ECMAScript and the files were .mjs files, while the https://github.com/trpc/examples-next-prisma-websockets-starter/blob/main/tsconfig.server.json was actually compiling the project as cjs. After some tweaks to the build files, namely, changing them from mjs to js and fixing the imports/requires inside, I actually managed to run the whole thing.
ofc, that wasn't a permanent solution as no sane person would manually go to edit the build files after every build, so I just ended up removing the env handler thingy because I was too lazy to rework it and it ain't really that much useful for the scope of my project
PS > I am using an old version of t3, i.e 6.11.4 so this may perhaps not be an issue which can be reproduced on v7 >