I'm currently working node-express with typescript, I'm using absolute import path through tsconfig.json file's baseUrl and paths, and run server with ts-node and using tsconfig-paths module to ts-node can recognize my tsconfig absolute path on run time. I have no problem with running server through npm start,
But whenever I started server with debugging mode on vscode, It seems cannot resolve my tsconfig's path and throwing error cannot find module 'my absolute module path'. here is my tsconfig.json file and package.json file
tsconfig.json
{
"compilerOptions": {
"outDir": "./dist",
"moduleResolution": "node",
"sourceMap": true,
"module": "commonjs",
"allowJs": true,
"target": "es5",
"noUnusedParameters": false,
"allowUnreachableCode": true,
"allowUnusedLabels": true,
"lib": [
"es2015"
],
"baseUrl": ".",
"paths": {
"@routes": [
"src/routes/*"
],
"@client": [
"../client/*"
]
},
}
}
package.json - scripts
"scripts": {
"test": "jest --watchAll --runInBand",
"coverage": "jest --coverage",
"start": "ts-node -r tsconfig-paths/register src/index.ts",
"server": "./node_modules/nodemon/bin/nodemon.js",
"client": "npm start --prefix ../client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
note that I attach "tsconfig-paths/register" on npm start script. and here is my debugging mode setting in launch.json launch.json
{
"name": "TS File",
"type": "node",
"request": "launch",
"args": [
"${workspaceRoot}/server/src/index.ts"
],
"runtimeArgs": [
"--nolazy",
"-r",
"ts-node/register"
],
"cwd": "${workspaceRoot}/server",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart",
"console": "integratedTerminal"
}
How can I set dubugging mode to resolve my tsconfig.json's path. and is there any way to use absolute path with vscode debugger? (I've tried put "tsconfig-paths/register" on "runtimeArgs" but did not work)