nextJS trpc subscriptions using createEnv
I am following this (https://github.com/trpc/examples-next-prisma-websockets-starter) example, in order to try and integrate my next js app with trpc sockets. In this example they define a standalone file src/server/prodServer.ts & src/server/wssDevServer.ts . Ideally I would not like to have two seperate file's for if im running in development, or production - I would rather programatically dictate the behaviour of how the server is initialised based on the NODE_ENV env variable, for that reason I'm trying to launch my copy of prodServer in development mode (without first building).
To run this file in development mode, I am using a similar command as they do in the example (see package.json):
cross-env PORT=3001 tsx watch src/server/server.ts
.
When I run this command, @t3-oss/env-nextjs
createEnv complains that it cannot find any of the .env variables that it should expect, meaning it is not reading them from the file where they are specified. I believe this is something to do with me using tsx, as the enviroment variables are read in fine if use next dev
to run the project (without the custom wss server).
I have tried putting my enviroment variables in both a .env.local file, aswell as a .env file. Neither seems to allow createEnv to pick up on them, while using tsx. Note, I would be fine to use something other than tsx to run the file - my actual problem is that I wish to implement subscription support for trpc into my next app, the linked project is the only implemenation I could find online - so I am going off of their approach, if anyone can suggest another approach - please do.GitHub
GitHub - trpc/examples-next-prisma-websockets-starter: 🏓 tRPC Next....
🏓 tRPC Next.js WebSocket Starter. Contribute to trpc/examples-next-prisma-websockets-starter development by creating an account on GitHub.
0 Replies