I am facing an issue with resolving non-relative modules in TypeScript. I have tried using baseUrl
, paths
, and other methods, but none seem to work...
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"esModuleInterop": true,
"module": "commonjs",
"sourceMap": true,
"strict": true,
"target": "esnext",
"typeRoots": ["node_modules/@types"]
}
}
Directory structure of the project:
root
├─src
├── APIs
├── config
├── constants
├── middlewares
├── models
├── routes
├── services
- foo.ts
├── utils
└── app.ts
In app.ts
import foo from 'src/services/foo'
When running with ts-node src/app.ts
, I encounter the following error:
Cannot find module 'src/services/foo'