Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Last active May 16, 2024 16:38
Show Gist options
  • Save cecilemuller/2963155d0f249c1544289b78a1cdd695 to your computer and use it in GitHub Desktop.
Save cecilemuller/2963155d0f249c1544289b78a1cdd695 to your computer and use it in GitHub Desktop.
Run ts-node in VSCode Debugger
{
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
"args": ["src/script.ts", "--example", "hello"],
"cwd": "${workspaceRoot}",
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**", "node_modules/**"]
}
]
}
@DLatheron
Copy link

I have literally wasted two evenings trying to get my typescript running under VSCode (even though it runs fine using ts-node) - I was just about to throw in the towel and spend the rest of the evening screaming at the moon...

Thank you so much for sharing ❤️

@noirlyrik
Copy link

thanks a lot!

@magickeyyy
Copy link

@rutexd
Copy link

rutexd commented Mar 1, 2023

It actually worked without any problems from first try. Awesome!! 👍

@d0zingcat
Copy link

node-ter

You saved my life! thx!

@kkkkkkhx
Copy link

kkkkkkhx commented Mar 8, 2023

ok

@mfeeney
Copy link

mfeeney commented Apr 14, 2023

I've had the following config working forever without issue, but after upgrading to typescript 5 and apollo server 4, all of the sudden it doesn't like it anymore...

{ "version": "0.2.0", "configurations": [ { "name": "Server", "type": "node", "request": "launch", "runtimeExecutable": "node", "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"], "resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"], "args": ["src/index.ts"], "env": { "NODE_ENV": "local" }, "cwd": "${workspaceRoot}", "internalConsoleOptions": "openOnSessionStart", "skipFiles": ["<node_internals>/**", "node_modules/**"] } ] }

I end up getting this, which looks like it's not skipping the node_modules like it should
/node_modules/@apollo/server/dist/cjs/ApolloServer.js:70 const nodeEnv = config.nodeEnv ?? process.env.NODE_ENV ?? '';

Anyone else seen anything like this?

@mcustiel
Copy link

Thank you very much. I used your config to be able to debug typescript in neovim using dap.

@L9m
Copy link

L9m commented Jun 11, 2023

no type checking and need to use tsconfig-paths to resolve paths

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "runtimeArgs": ["-r", "ts-node/register/transpile-only", "-r", "tsconfig-paths/register"],
            "program": "${workspaceFolder}/packages/lerna/src/cli.js",
            "args": ["version"],
            "console": "integratedTerminal",
            "cwd": "${workspaceFolder}",
            "internalConsoleOptions": "neverOpen",
        }
    ]
}

@pablezhang
Copy link

Error: Cannot find module 'ts-node/register/transpile-only'

fixed this by install ts-node locally

npm link ts-node

// or 

yarn add -D ts-node

@iulo thanks,u save my day.

@silvioprog
Copy link

Works perfectly for me

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "ts-node",
      "type": "node",
      "request": "launch",
      "args": ["${relativeFile}"],
      "runtimeArgs": ["-r", "ts-node/register"],
      "cwd": "${workspaceRoot}",
      "protocol": "inspector",
      "internalConsoleOptions": "openOnSessionStart"
    }
  ]
}

Not all heroes wear capes! 😀

@Davetwo
Copy link

Davetwo commented Mar 8, 2024

Thanks!
General purpose ts-node run opened file (using ${file}) whereas process-library is the base-folder of the ts app:

  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  // https://gist.github.com/cecilemuller/2963155d0f249c1544289b78a1cdd695
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "ts-node",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "node",
      "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],

      "args": ["${file}"],
      
      "cwd": "${workspaceRoot}/process-library",
      "internalConsoleOptions": "openOnSessionStart",
      "skipFiles": ["<node_internals>/**", "node_modules/**"]
    }
    
  ]
}

@prmichaelsen
Copy link

Wow, I have never had a VS Code debug configuration work perfectly the first time I ran it. Thanks a bunch

@yolpsoftware
Copy link

yolpsoftware commented May 16, 2024

Unfortunately, this does not work with "console": "internalTerminal", I'm getting Cannot find module ts-node/register/transpile-only. (ts-node is installed locally as a dev dependency - I tried everything, deleting node_modules, restarting..).

With "console": "externalTerminal" it seems to work.

Any idea why this has to do with the "console" setting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment