Skip to content

vscode launch config ts-node with tsconfig-paths #777

Closed

Description

@yantrab

Can you please give me example of how to config vs-code launch with ts-node and tsconfig-path?
Tanks.

Activity

  1. thomas-darling commented on Feb 9, 2019

    @thomas-darling

    Yeah, I can't figure this out either...

    The readme explains how to configure a vscode task that launches a .ts file, but how do we pass e.g. the --project argument in this case?

    This is what I'm trying, but it just gives me a bad option: --project error - which actually makes sense, if it, as I understand it, just registers ts-node as a loader for .ts files.

    {
      "type": "node",
      "request": "launch",
      "name": "Develop",
      "runtimeArgs": [
        "-r",
        "ts-node/register"
      ],
      "args": [
        "--project",
        "${workspaceRoot}/tools/tsconfig.json",
        "${workspaceRoot}/tools/scripts/develop.ts"
      ],
      "console": "integratedTerminal"
    }

    And on a side note, the above is actually not even what I originally set out to achieve.
    What I really wanted, was to launch and debug an NPM package script, defined in package.json as:

    "develop": "ts-node --project 'tools/tsconfig.json' 'tools/scripts/develop'"

    But I cannot for the life of me figure out how to make either of those work.

    Any guidance would be much appreciated :-)

  2. thomas-darling commented on Feb 9, 2019

    @thomas-darling

    Right, it actually looks like #734 answers my first question. I'd still love to know if there's a way to just debug the NPM package script though, as replicating all the scripts in the vscode launch config is not exactly ideal.

    Oh, and please merge #738, so no more time will be wasted on this :-)

  3. yantrab commented on Feb 9, 2019

    @yantrab
    Author
        {
            "type": "node",
            "request": "launch",
            "name": "server",
            "runtimeArgs": [
                "-r",
                "ts-node/register",
                "-r",
                "tsconfig-paths/register"
            ],
            "args": [
                "${workspaceFolder}/src/app.ts"
            ]
        }
    

    @thomas-darling what is project pipe do?

  4. thomas-darling commented on Feb 9, 2019

    @thomas-darling

    Hmm, now I wonder if we're actually talking about two different things here...

    I thought this issue was about how to specify the path to the tsconfig.json file, which is what the --project argument is for. But what you are doing there looks like something entirely different, so if that's the case, sorry for hijacking the issue :-)

  5. caseyduquettesc commented on Feb 16, 2019

    @caseyduquettesc

    The answer is in the README

    {
      "version": "0.2.0",
      "configurations": [
        {
          "type": "node",
          "request": "launch",
          "name": "Launch Server",
          "protocol": "inspector",
          "runtimeVersion": "8.11.4",
          "runtimeArgs": ["-r", "ts-node/register", "-r", "tsconfig-paths/register"],
          "args": ["src/main.ts"],
          "cwd": "${workspaceFolder}",
          "console": "integratedTerminal",
          "internalConsoleOptions": "neverOpen",
          "env": {
            "TS_NODE_PROJECT": "tsconfig.json",
            "TS_NODE_TRANSPILE_ONLY": "true"
          }
        }
      ]
    }
  6. stepli1010 commented on Mar 28, 2019

    @stepli1010

    The answer is in the README

    {
      "version": "0.2.0",
      "configurations": [
        {
          "type": "node",
          "request": "launch",
          "name": "Launch Server",
          "protocol": "inspector",
          "runtimeVersion": "8.11.4",
          "runtimeArgs": ["-r", "ts-node/register", "-r", "tsconfig-paths/register"],
          "args": ["src/main.ts"],
          "cwd": "${workspaceFolder}",
          "console": "integratedTerminal",
          "internalConsoleOptions": "neverOpen",
          "env": {
            "TS_NODE_PROJECT": "tsconfig.json",
            "TS_NODE_TRANSPILE_ONLY": "true"
          }
        }
      ]
    }

    good~

  7. Guihgo commented on Aug 30, 2020

    @Guihgo

    create scripts on package.json and use the runtimeExecutable and runtimeArgs on .vscode/launch.json:

    package.json

    {
      "name": "someproject",
      "version": "1.0.0",
      "description": "Some project",
      "main": "index.js",
      "author": "Guihgo",
      "license": "MIT",
      "scripts": {
        "dev": "tsnd -r tsconfig-paths/register --transpile-only --respawn --ignore-watch node_modules src/index.ts",
        "build": "tsc",
        "test": "jest"
      },
      "private": false,
      "devDependencies": {
           [...]
      },
      "dependencies": {}
    }

    .vscode/launch.json

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "DEV",
                "type": "node",
                "request": "launch",
                "restart": true,
                "skipFiles": [
                    "<node_internals>/**"
                ],
                "runtimeExecutable": "yarn",
                "runtimeArgs": [
                    "dev"
                ]
            },
            {
                "name": "TEST",
                "type": "node",
                "request": "launch",
                "restart": true,
                "skipFiles": [
                    "<node_internals>/**"
                ],
                "runtimeExecutable": "yarn",
                "runtimeArgs": [
                    "test"
                ]
            }
        ]
    }

    in runtimeExecutable you can set to npm, but i thinks you needs add "run" argumment on runtimeArgs as following

    .vscode/launch.json

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "DEV",
                "type": "node",
                "request": "launch",
                "restart": true,
                "skipFiles": [
                    "<node_internals>/**"
                ],
                "runtimeExecutable": "npm",
                "runtimeArgs": [
                    "run",
                    "dev"
                ]
            },
            {
                "name": "TEST",
                "type": "node",
                "request": "launch",
                "restart": true,
                "skipFiles": [
                    "<node_internals>/**"
                ],
                "runtimeExecutable": "npm",
                "runtimeArgs": [
                    "run",
                    "test"
                ]
            }
        ]
    }
  8. locked and limited conversation to collaborators on Sep 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions