Has anyone here gotten a working VSCode `launch.js...
# orm-help
d
Has anyone here gotten a working VSCode
launch.json
working with nodemon that is running ts-node?
p
This is something I started to work on last night but didn't get time to finish the configuration. https://github.com/Microsoft/vscode/issues/40430 Maybe this will be of help?
d
Interesting. I tried the latest comment’s setup, and got it running successfully, but the debugger couldn’t attach to the port, oddly enough. You run across the same thing?
Copy code
{
  "name": "Launch via nodemon",
  "type": "node",
  "request": "launch",
  "protocol": "inspector",
  "cwd": "${workspaceFolder}",
  "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
  "runtimeArgs": [
    "--exitcrash",
    "-e",
    "ts,graphql",
    "-x",
    "${workspaceRoot}/node_modules/.bin/ts-node"
  ],
  "args": [
    "${workspaceRoot}/src/index.ts"
  ],
  "restart": true,
  "console": "integratedTerminal",
  "internalConsoleOptions": "openOnSessionStart",
  "skipFiles": [
    "node_modules/**",
    "<node_internals>/**"
  ]
}
p
I am going to try it in few hours, at work right now. I am having a weird issue where any changes to the TS file would automatically start the server without any log. It's bit frustrating as I can't seem to find the cause of it.
d
Curious if you are able to get it working. I haven’t found a way to debug in my graphql server other than console.log 🙈
p
I got it working. Place these 2 files inside .vscode.
Let me know if this configuration works for you.
d
Interesting. Are you using nodemon and TS-Node? Or straight TypeScript compiler?
p
launch.json is inside .vscode. config.json is in root folder and add
"start:inspect": "nodemon --config config.json"
in your package.json
you can either run using npm npm run start:inspect or yarn yarn start:inspect
Once you have the server running, you can switch the debugger config to Attach and it should bind to localhost:5858 which the inspector is running on.
I can't seem to toggle any breakpoints tho. Let me know if it works for you.
d
I got it all figured out on my end. I can start the debugger one of two ways:
1. Using the VSCode Debugger Extension, I can run the “Launch and Debug” task:
Copy code
{
  "name": "Launch and Debug",
  "type": "node",
  "request": "launch",
  "protocol": "inspector",
  "cwd": "${workspaceFolder}",
  "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/dotenv",
  "runtimeArgs": [
    "--",
    "${workspaceRoot}/node_modules/.bin/nodemon",
    "-e",
    "ts,graphql",
    "-x",
    "node"
  ],
  "args": [
    "-r",
    "ts-node/register",
    "src/index.ts"
  ],
  "restart": true,
  "console": "integratedTerminal",
  "internalConsoleOptions": "openOnSessionStart",
  "skipFiles": [
    "node_modules/**",
    "<node_internals>/**"
  ]
}
Or 2. I can execute a debug script and then use a launch.json config to attach:
"start:debug": "dotenv -- nodemon -e ts,graphql -x node --inspect -r ts-node/register src/index.ts",
Copy code
{
      "type": "node",
      "request": "attach",
      "name": "Attach to Process",
      "port": 9229,
      "restart": true,
      "protocol": "inspector"
    },
Breakpoints are working for me.
👍 1