I have a nestjs project in vscode and in debugging mode the changes in code does not take effect. Breakpoints hit normally, however, but for example a changed variable values are not to be seen - i.e. they stay as the previous ones (the ones before change).
My launch.json is the following:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Nest Framework",
"runtimeExecutable": "nodemon",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register", "--config", "nodemon-debug.json"],
"program": "${workspaceFolder}/src/main.ts",
"autoAttachChildProcesses": true,
"restart": true
}
]
}
And the nodemon-debug.json file has the following:
{
"watch": ["src"],
"ext": "ts, js",
"ignore": ["src/**/*.spec.ts"]
}
And strangely enough, when I make change in the code, the nodemon really registers it and restart the app, as can seen from the console:
C:\...\AppData\Roaming\npm\nodemon.cmd --nolazy -r ts-node/register --config nodemon-debug.json .\dist\main.js
[nodemon] 2.0.18
c:\...\AppData\Roaming\npm\node_modules\nodemon\lib\utils\log.js:34
[nodemon] to restart at any time, enter `rs`
c:\...\AppData\Roaming\npm\node_modules\nodemon\lib\utils\log.js:34
[nodemon] watching path(s): src\**\*
c:\...\AppData\Roaming\npm\node_modules\nodemon\lib\utils\log.js:34
[nodemon] watching extensions: ts,js
c:\...\AppData\Roaming\npm\node_modules\nodemon\lib\utils\log.js:34
[nodemon] starting `node --nolazy -r ts-node/register .\dist\main.js`
c:\...\AppData\Roaming\npm\node_modules\nodemon\lib\utils\log.js:34
[WEB] http://localhost:3000
Can anyone figure out why changes are not taking effect?
I finally found solution from this https://stackoverflow.com/a/63325135/7625979
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Nest Framework",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"start:debug",
"--",
"--inspect-brk"
],
"autoAttachChildProcesses": true,
"restart": true,
"sourceMaps": true,
"stopOnEntry": false,
"console": "integratedTerminal",
}
]
}
This solution indeed works for me perfectly and does not need either the vscode's setting: Debug > Javascript: Auto Attach Filter to "Always". Also console: integratedTerminal -option is handy because debug-info comes directly into the same console. Also, nodemon-debug.json is not now needed.
Script command in Package.json file are now:
"scripts": {
...
"start:debug": "nest start --debug --watch",
...
}
It seems that "--watch" is still needed here for the code changes to take effect.