Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

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

Closed
yantrab opened this issue Feb 8, 2019 · 7 comments
Closed

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

yantrab opened this issue Feb 8, 2019 · 7 comments

Comments

@yantrab
Copy link

yantrab commented Feb 8, 2019

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

@thomas-darling
Copy link

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 :-)

@thomas-darling
Copy link

thomas-darling commented Feb 9, 2019

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 :-)

@yantrab
Copy link
Author

yantrab commented Feb 9, 2019

    {
        "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?

@thomas-darling
Copy link

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 :-)

@caseyduquettesc
Copy link

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"
      }
    }
  ]
}

@stepli1010
Copy link

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~

@Guihgo
Copy link

Guihgo commented Aug 30, 2020

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"
            ]
        }
    ]
}

@TypeStrong TypeStrong locked and limited conversation to collaborators Sep 19, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants