Every time I attempt to import a module in my NextJS custom server app, like
import { registerStartOfGuildTriviaListener } from '@/lib/trivia-manager';
, the module is reloaded instead of using the previously loaded version. This poses an issue for me because I store important data in this module that I need to access across various parts of my application. However, whenever I try to retrieve that data elsewhere, it has been reset and is no longer available.
I have spent the last few days searching for a solution without success. I even attempted using an absolute path instead of the path alias (@) but it did not resolve the issue.
Below is my entire 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"
]
}
To compile with tsx, I use: npx tsx server.ts