When I try to import from a module in my NextJS custom server app such as import { registerStartOfGuildTriviaListener } from '@/lib/trivia-manager';
in more than one place, the module gets reloaded rather than using what has already been loaded. This is a problem for me because I am keeping some data in this module that I would like to use all over my app, but when I go to try and get that data elsewhere, it has been re-initialized and no longer exists.
I have been looking for a solution for the last couple days and I just cannot find one. I have tried using an absolute path rather than the path alias (@) and it still doesn’t work FYI.
Here is my complete tsconfig.json file:
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"typeRoots": [
"./types"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"baseUrl": ".",
"paths": {
"@/*": [
"./*"
],
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}
I am using the tsx compiler like so: npx tsx server.ts