Skip to content
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

Specify a different tsconfig when launching debugger in VS Code #734

Closed
Zlatkovsky opened this issue Nov 23, 2018 · 2 comments
Closed

Specify a different tsconfig when launching debugger in VS Code #734

Zlatkovsky opened this issue Nov 23, 2018 · 2 comments
Labels
question Support requests. We tend not to answer these on Github. Nowadays I convert to Discussion instead.

Comments

@Zlatkovsky
Copy link
Contributor

Note sure if it's a feature gap or a documentation bug -- but I have been unable to use VS Code debugging for my use case.

If I run tsnode on the commandline or from script in package.json, it works beautifully:

"precompile": "ts-node --project ../../scripts/tsconfig.json scripts/precompile.ts

However, when I tried to put it into a VS Code launch config, such as this:

    {
      "type": "node",
      "request": "launch",
      "name": "Editor precompile script",
      "runtimeArgs": ["-r", "ts-node/register"],
      "args": ["--project", "../../scripts/tsconfig.json", "scripts/precompile.ts"],
    },

It fails with

C:\Program Files\nodejs\node.exe: bad option: --project ../../scripts/tsconfig.json

On the other hand, if I omit the --project part and only have

      "args": ["scripts/precompile.ts"],

then the command fails with the same error that I would get if I omitted --project on the commandline. The error is

import fs from 'fs-extra';
       ^^
SyntaxError: Unexpected identifier

and results from my top-level tsconfig.json targeting a different type of module -- which is why I created the separate tsconfig in the first place, for tsnode's usage.

Is there any way to pipe this through to the VSCode launch config?

Thanks!

@blakeembrey
Copy link
Member

You need to use environment variables for this. Node.js doesn't understand ts-node arguments directly, so we have a "backdoor" via environment variables. In VS Code, you can set environment variables through the launch.json. There's some (not great) documentation in https://code.visualstudio.com/Docs/editor/debugging, I think it should look something like: "env": { "TS_NODE_PROJECT": "path-here" } (not tested).

@blakeembrey blakeembrey added the question Support requests. We tend not to answer these on Github. Nowadays I convert to Discussion instead. label Nov 23, 2018
@Zlatkovsky
Copy link
Contributor Author

Yep, that worked beautifully! Thanks, @blakeembrey! Added PR #738 to make a note of this in the readme, if you think that would be useful to have there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Support requests. We tend not to answer these on Github. Nowadays I convert to Discussion instead.
Projects
None yet
Development

No branches or pull requests

2 participants