Skip to content

[Regression] Debugging of typescript node apps has been broken #40430

Closed

Description

  • VSCode Version:
    Code 1.19.0 (816be67, 2017-12-14T12:06:43.492Z)
    Code - Insiders 1.20.0-insider (08ec160, 2017-12-
    15T05:15:38.886Z)
  • OS Version: Windows_NT x64 10.0.16299
  • Extensions: none

Debugging works fine in Code 1.18.1 (929bacb, 2017-11-16T18:32:36.023Z). Have to revert to it until the bug is fixed.

Steps to Reproduce:

  1. clone https://github.com/deilan/node-typescript-vscode
  2. npm install or yarn install
  3. Launch Launch via nodemon debugging configuration

Result:
The process has been started, debugger couldn't start with the following error message:

Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:35247).

Activity

  1. added
    debug
    on Dec 18, 2017
  2. weinand commented on Dec 18, 2017

    @weinand
    Contributor

    Your launch config is wrong (and it was only working in previous versions of VS Code because of bug #16173).
    The problem is that you are passing all arguments via the "runtimeArgs" attribute. This makes it difficult for VS Code to insert the "--inspect-brk" argument it the right location.

    Instead you should only pass nodemon arguments via "runtimeArgs", then use the "program" attribute for your "real" program and then the "real" arguments through the "args" attribute.
    (So if you remove the "runtimeExecutable" and "runtimeArgs" attributes from the launch config, then you should end up with a launch config that runs your program without nodemon.)
    E.g.:

    {
        "name": "Launch via nodemon",
        "type": "node",
        "request": "launch",
        "protocol": "inspector",
        "cwd": "${workspaceRoot}",
        "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
        "runtimeArgs": [
            "--exitcrash",
            "--config", "${workspaceRoot}/nodemon.json",
            "--exec", "${workspaceRoot}/node_modules/.bin/ts-node",
        ],
        "program": "${workspaceRoot}/src/index.ts",
        "args": [
            "--project", "${workspaceRoot}/tsconfig.development.json"
        ],
        "restart": true,
        "console": "integratedTerminal",
        "internalConsoleOptions": "openOnSessionStart",
        "skipFiles": [
            "node_modules/**",
            "<node_internals>/**"
        ]
    },
    

    This launch config should work on all versions of VS Code so you can try it with 1.18.1 and if it works you can safely upgrade to 1.19.

    Let me know if this works.

  3. added
    info-needed
    on Dec 18, 2017
  4. Deilan commented on Dec 18, 2017

    @Deilan
    Author

    Andre Weinand (@weinand) Thanks for the explanation. I've tried the suggested debug configuration. Unfortunately I've got the following error message on both 1.18.1 and 1.20.0:

    Cannot launch program 'c:\Dev\node-typescript-vscode\src\index.ts' because corresponding JavaScript cannot be found.

    There's no outFiles and as far as I understand specifying them doesn't make sense. Of course if I specify outFiles as an empty array I get:

    Cannot launch program 'c:\Dev\node-typescript-vscode\src\index.ts' because corresponding JavaScript cannot be found.

  5. weinand commented on Dec 18, 2017

    @weinand
    Contributor

    You do not seem to have an explicit build task that transpiles TS to JS.
    The ts-node seems to be the tool that transpiles in your case.
    That means VS Code cannot really know where the generated JS lives.
    But since ts-node takes care of it, VS Code does not really has to know.

    Remove the "program" attribute and insert the "${workspaceRoot}/src/index.ts" as the first argument of the "args" attribute just before "--project".

    {
        "name": "Launch via nodemon",
        "type": "node",
        "request": "launch",
        "protocol": "inspector",
        "cwd": "${workspaceRoot}",
        "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
        "runtimeArgs": [
            "--exitcrash",
            "--config", "${workspaceRoot}/nodemon.json",
            "--exec", "${workspaceRoot}/node_modules/.bin/ts-node",
        ],
        "args": [
            "${workspaceRoot}/src/index.ts",
            "--project", "${workspaceRoot}/tsconfig.development.json"
        ],
        "restart": true,
        "console": "integratedTerminal",
        "internalConsoleOptions": "openOnSessionStart",
        "skipFiles": [
            "node_modules/**",
            "<node_internals>/**"
        ]
    },
    
  6. Deilan commented on Dec 18, 2017

    @Deilan
    Author

    Yep, that worked. 1.18.1, 1.19.0 and 1.20.0. Thanks Andre Weinand (@weinand)!

  7. locked and limited conversation to collaborators on Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

debuginfo-needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions