I had meet the problem that resolve non-relative moduels in typescript. And try baseUrl
, paths
and so on, but it not works....
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"esModuleInterop": true,
"module": "commonjs",
"sourceMap": true,
"strict": true,
"target": "esnext",
"typeRoots": ["node_modules/@types"]
}
}
The project dirs:
root
├─src
├── APIs
├── config
├── constants
├── middlewares
├── models
├── routes
├── services
- foo.ts
├── utils
└── app.ts
in app.ts
import foo from 'src/services/foo'
And run with ts-node src/app.ts
.
But the error occurs:
Cannot find module 'src/services/foo'