How to attach the VSCode debugger to the ts-node command that uses env variables like the below one:
package.json:
{
"runMyScript": "ts-node -r dotenv/config --transpile-only tasks/migration/myScript.ts dotenv_config_path=./local.env"
}
I tried adding flags --respawn --inspect=4000 to the above command with below launch.json, but it didn't work:
launch.json:
{"configurations": [
{
"name": "RUN attach to DEV",
"type": "node",
"port": 4000,
"request": "attach",
"trace": true,
"skipFiles": ["<node_internals>/**"],
"restart": true
},
]}
.vscode/launch.json or add configurations to your existing configurations{
"version": "1.0.0",
"configurations": [
{
"name": "TS-Node",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/ts-node",
"runtimeArgs": [
"--transpile-only",
// if you use esm
"--esm"
],
"program": "${file}",
"cwd": "${workspaceRoot}",
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**", "node_modules/**"]
}
]
}
Run and Debug window on the left side of VSCode and run this configuration called TS-NodeIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With