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!
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).
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.
Most helpful comment
You need to use environment variables for this. Node.js doesn't understand
ts-nodearguments directly, so we have a "backdoor" via environment variables. In VS Code, you can set environment variables through thelaunch.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).