welp
welp15mo ago

Is it possible to create 2 routers inside a single file?

I am having an issue in which it is impossible to me to use a class instance within 2 routers. I tried declaring the routers in a single file and then exporting them, it doesn't work. The issue I am facing is this: https://github.com/vercel/next.js/issues/49309 Any insight/help would be greatly appreciated.
GitHub
Module imported in different files re-evaluated · Issue #49309 · ve...
Verify canary release I verified that the issue exists in the latest Next.js canary release Provide environment information Operating System: Platform: linux Arch: x64 Version: #1 SMP Wed Mar 2 00:...
4 Replies
Nick
Nick15mo ago
Can you share a bit more what you mean? Maybe a code example? Given that's a Next bug, if it really is that, I'm not sure we can help much here
welp
welp15mo ago
@Nick Lucas I am trying to use a singleton class instance which is storing a hash map of eventemitter objects which I want to use for subscriptions. What happens specifically is that when I emit an event, it is emitted on an instance that has no callbacks registered. This is due to the next bug, re-evaluating an import from an external file and replacing its pointer in memory with a newly empty created instance. The way I tried to avoid this, since I want to use that class instance in 2 routers, I tried to create my 2 routers inside a single file, declare the class instance in there and move on, but didn't work. I didn't try to merge the 2 routers into 1 however, I will do that tomorrow and get back to you.
Nick
Nick15mo ago
This definitely sounds like a weird bundling issue, or that Next is recreating your backend on each request (which may be a feature rather than a bug) Trpc itself is fine with you exporting 2 routers from the same file or having a singleton
welp
welp14mo ago
Yeah I don't know, I implemented redis and everything is working properly.