Upon building my typescript app and starting the app.js, I encountered this error:
node:internal/modules/cjs/loader:1050
throw err;
^
Error: Cannot find module 'controllers'
I suspect that the issue lies in how I am using import/export statements. For example, in my TypeScript file, I am importing like this:
import {
checkToken,
getUserInfo,
signIn,
signUp
} from 'controllers';
However, the compiled JavaScript dist uses a different approach:
const controllers_1 = require("controllers");
This is my tsconfig setup:
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"noImplicitAny": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"rootDirs": ["src"],
"baseUrl": "./src"
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}