I have this project structure:
How to configure tsconfig.json
for using paths
like @app/
, @server/
.
I try this:
{
"compilerOptions": {
"module": "CommonJS",
"target": "es5",
"lib": [
"esnext",
"dom"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": false,
"baseUrl": "..",
"paths": {
"@app/*": [
"app/*"
],
"@server/*": [
"server/*"
]
}
},
"include": [
"."
]
}
Same config works with webpack
and ts-loader
, but when i run npx ts-node server/index.ts
i got error:
npx ts-node server/index.ts
Error: Cannot find module '@server/a'
server/index.ts
:
import a from '@server/a'
console.log('This is index.ts')
a()