Skip to content

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

Closed

Description

@Zlatkovsky

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!

Activity

  1. blakeembrey commented on Nov 23, 2018

    @blakeembrey
    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).

  2. added
    questionSupport requests. We tend not to answer these on Github. Nowadays I convert to Discussion instead.
    on Nov 23, 2018
  3. Zlatkovsky commented on Nov 27, 2018

    @Zlatkovsky
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionSupport requests. We tend not to answer these on Github. Nowadays I convert to Discussion instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions