-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to debug typescript file #9
Comments
does it work without |
No :( |
Try to run it without debugger, try to run it with just |
Same for me, but with |
Debug with restart is working for me on macOS 10.13.4 and Node.js 8.9.4 with the following VS Code debug configuration: {
"name":"Launch via nodemon",
"type":"node",
"request":"launch",
"protocol":"inspector",
"cwd":"${workspaceRoot}",
"runtimeExecutable":"${workspaceRoot}/node_modules/.bin/ts-node-dev",
"args":[
"${workspaceRoot}/src/index.ts"
],
"restart":true
} The only issue I've encountered is ts-node-dev won't restart if execution is stopped at a breakpoint. |
I found the solution that work for me. Under .vscode ( folder ) you should create 2 files:
launch.json:
tasks.json:
pacckage.json ( scripts section )
To Run you should press Shift + command + B ( Tasks - > Run Build Task ). |
Just Tools:
package.json {
"scripts": {
"debug": "cross-env TZ=UTC NODE_ENV=development tsnd --inspect --respawn src/main.ts"
}
} launch.json {
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Typescript Server",
// "processId": "${command:PickProcess}",
"protocol": "inspector",
"port": 9229,
"restart": true,
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
} Usage:
|
@joseluisq thanks, this worked for me!
|
@montera82 if you want to debug in docker container check out: Basically, it should works with minimal tweaks. |
Works fine for me with this launch task:
|
Expanding on @joseluisq's above - The solution nearly worked for me. I'm unsure if it's because of my project settings, or if something in the dependencies have changed with time. The above launch.json settings worked great to attach the debugger, however I found all of my breakpoints were appearing as Removing Updated instructions: Tools package.json {
...
"scripts": {
...
"debug": "ts-node-dev --inspect --respawn --transpileOnly src/main.ts"
},
...
} .vscode/launch.json {
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Typescript Server",
"protocol": "inspector",
"port": 9229,
"restart": true,
"cwd": "${workspaceRoot}"
}
]
} Usage:
|
@gintsgints I tried your solution as I don't want to have to manually run a command and then attach Have you run into this? |
No I have not. Check logs, may be somthing about port settings. |
Leaving my launch.json file here for anyone who may find it useful:
where <src/your_entry_point.ts> is the entry point of your application. This uses tsconfig-paths to register custom paths registered in tsconfig.json. if your app doesn't use this library, remove the lines :
I prefer this method as it doesn't require starting the application in a console then attaching the debugger on a seperate (vscode integrated) terminal. It will launch your application, attach the debugger, and register all breakpoints. |
Yes I have run into this... |
Adding to this, currently VS Code seems to be having some issues reattaching. My program crashes with This seems to be working for me so far: {
"name": "ts-node-dev",
"type": "node",
"request": "launch",
"protocol": "inspector",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/ts-node-dev",
"args": [
"--inspect",
"--no-notify",
"--transpileOnly",
"--respawn",
"${workspaceRoot}/src"
],
"console": "integratedTerminal",
"restart": true
} |
I had to add my |
It is how it works for me now, with restart and registered paths from tsconfig.json. Which troubles I resolved before I get this:
Command:
Output:
Just put to the tsconfig.json of project that you are trying to compile: Summaryts-node-dev debug config with typescript paths and auto reload: {
"name": "Server tools",
"type": "node",
"request": "launch",
"protocol": "inspector",
"restart": true,
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ts-node-dev",
"cwd": "${workspaceFolder}/apps/server/tools/${input:toolName}",
"internalConsoleOptions": "openOnSessionStart",
"args": [
"--inspect",
"--respawn",
"--no-notify",
"--require",
"tsconfig-paths/register",
"./src/main.ts"
]
} @whitecolor as I can see lots of people comes to your lib after troubles with nodemon through this issue https://stackoverflow.com/a/50528031 and in most cases they trying to setup debugging. Would it be a good idea to put something like "troubleshooting" section to readme for such folks? |
I'm getting It seems that it's when I try to import sequelize, but I can't see what I'm doing wrong. |
@rochapablo probably trying to run some code that contains |
After an extensive amount of trial and error, this config seems to have worked for me:
|
@joseluisq , Here it's works, it started normally , but I can't use break point. Could someone help me please? "scripts": { launch.json
|
This is what I used. The important part was making sure you pass the "--inspector" flag to ts-node-dev. e.g.
There is also the auto attach feature you can look at. Check here: |
HI Dev,
I try to debug typescript files, in visual studio code.
to run the code I using yarn ts-node-dev server.
Need help :)
configuration:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"port": 5858,
"outFiles": []
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/server.ts",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"cwd": "${workspaceRoot}"
}
]
}
error:
Cannot connect to runtime; make sure that runtime is in 'legacy' debug mode.
The text was updated successfully, but these errors were encountered: