Skip to content

Instantly share code, notes, and snippets.

@ThorsAngerVaNeT
Forked from ehaynes99/vscode-debug-current.md
Created September 28, 2023 12:30
Show Gist options
  • Save ThorsAngerVaNeT/cba280118a12a7561aba4d199246d208 to your computer and use it in GitHub Desktop.
Save ThorsAngerVaNeT/cba280118a12a7561aba4d199246d208 to your computer and use it in GitHub Desktop.

Revisions

  1. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ These launch configs will allow you to debug typescript files directly from VSCo
    {
    "type": "node",
    "request": "launch",
    "name": "ts-node current file",
    "name": "ts-node - current file",
    "runtimeExecutable": "npx",
    "runtimeArgs": ["-y", "ts-node"],
    "program": "${file}",
    @@ -19,7 +19,7 @@ These launch configs will allow you to debug typescript files directly from VSCo
    {
    "type": "node",
    "request": "launch",
    "name": "watch current file",
    "name": "ts-node - watch current file",
    "runtimeExecutable": "npx",
    "runtimeArgs": [
    "-y",
  2. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Debugging TypeScript in VSCode
    # Debugging TypeScript with ts-node in VSCode
    These launch configs will allow you to debug typescript files directly from VSCode. It will honor the `tsconfig` and resolve node modules properly. You do not need to install `ts-node` or `nodemon`, as everything is run using `npx`. The first

    ## Launch Config
  3. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,9 @@ These launch configs will allow you to debug typescript files directly from VSCo
    "nodemon",
    "-q",
    "--exec",
    "$(echo npx -y ts-node ${file})"
    "npx",
    "-y",
    "ts-node"
    ],
    "program": "${file}",
    "cwd": "${fileDirname}",
  4. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 2 additions and 57 deletions.
    59 changes: 2 additions & 57 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # Debugging TypeScript in VSCode
    These launch configs will allow you to debug typescript files directly from VSCode. It will honor the `tsconfig` and resolve node modules properly. You do not need to install `ts-node` or `nodemon`, as everything is run using `npx`.
    These launch configs will allow you to debug typescript files directly from VSCode. It will honor the `tsconfig` and resolve node modules properly. You do not need to install `ts-node` or `nodemon`, as everything is run using `npx`. The first

    ## Launch Config
    ```json
    @@ -46,63 +46,8 @@ npx -y ts-node example.ts
    ```
    It's better to use `cwd` in this way, as this allows for nested `tsconfig` files as may appear in a monorepo.

    The second one had to be a bit sneaky because of... quirks. `nodemon` recently added TypeScript support, but internally it simply runs the `ts-node` command instead of `node`. However, to avoid the dependency for those using regular JS, they didn't add `ts-node` to its dependencies. You could avoid this by installing it in the project with `npm i -D ts-node`, but I wanted these to work without installing anything. This can be solved with `nodemon`'s `--exec` option by compounding `npx` scripts:
    The second one had to be a bit sneaky because of quirks in `nodemon`. They recently added TypeScript support, but internally it simply runs the `ts-node` command instead of `node`. However, to avoid the dependency for those using regular JS, they didn't add `ts-node` to its dependencies, so `npx nodemon` doesn't supply the dependency. You could avoid this by installing it in the project with `npm i -D ts-node`, but I wanted these to work without installing anything. This is solved with the `--exec` option by compounding `npx` scripts. The second config is equivalent to:
    ```
    cd src/path/to
    npx -y nodemon -q --exec 'npx -y ts-node' ./example.ts
    ```

    HOWEVER, you can't directly do this with `runtimeArgs` in a launch config, because VSCode messes up the quotes. To hack around this, we use command expansion of the linux shell (sorry Windows users) combined with `echo`. The results of command expansion are




    The `runtimeExecutable` is `npx`, which allows running modules directly from `npm`.

    ## Debug current file
    This launch config will run the current typescript file in the debugger. This does not require `ts-node` to be installed, as it runs through `npx`.
    ```jsonc
    {
    "configurations": [
    {
    "type": "node",
    "request": "launch",
    "name": "ts-node current file",
    "runtimeExecutable": "npx",
    "runtimeArgs": ["-y", "ts-node"],
    "program": "${file}",
    "cwd": "${fileDirname}",
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen",
    },
    ],
    }
    ```

    # Live Reloads
    If you want live reloading, you can use the combination of `nodemon` and `ts-node`. Unfortunately, I havent found a way to do this without installing `ts-node` (see below). As in all cases, I strongly recommend adding it as a `devDependency` in your project rather than installing globally.

    ```
    npm i -D ts-node
    ```

    Then you can use this configuration:
    ```jsonc
    {
    "configurations": [
    {
    "type": "node",
    "request": "launch",
    "name": "watch current file",
    "runtimeExecutable": "npx",
    "runtimeArgs": ["-y", "nodemon", "-q"],
    "program": "${file}",
    "cwd": "${fileDirname}",
    "restart": true,
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen"
    },
    ],
    }
    ```

  5. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,9 @@ cd src/path/to
    npx -y nodemon -q --exec 'npx -y ts-node' ./example.ts
    ```

    HOWEVER, you can't directly do this with `runtimeArgs` in a launch config, because VSCode messes up the quotes. To hack around this, we use
    HOWEVER, you can't directly do this with `runtimeArgs` in a launch config, because VSCode messes up the quotes. To hack around this, we use command expansion of the linux shell (sorry Windows users) combined with `echo`. The results of command expansion are




    The `runtimeExecutable` is `npx`, which allows running modules directly from `npm`.
  6. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ cd src/path/to
    npx -y nodemon -q --exec 'npx -y ts-node' ./example.ts
    ```

    HOWEVER, you can't directly do this with `runtimeArgs` in a launch config, because VSCode messes up the quotes. To hack around this
    HOWEVER, you can't directly do this with `runtimeArgs` in a launch config, because VSCode messes up the quotes. To hack around this, we use


    The `runtimeExecutable` is `npx`, which allows running modules directly from `npm`.
  7. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -46,11 +46,13 @@ npx -y ts-node example.ts
    ```
    It's better to use `cwd` in this way, as this allows for nested `tsconfig` files as may appear in a monorepo.

    The second one had to be a bit sneaky because of the way that `nodemon` works. They recently added TypeScript support, but internally it simply runs the `ts-node` command instead of `node`. However, to avoid the dependency for those using regular JS, they didn't add `ts-node` to its dependencies. You could avoid this by installing it in the project with `npm i -D ts-node`, but I wanted these to work without installing anything. This can be solved with `nodemon`'s `--exec` option by compounding `npx` scripts:
    The second one had to be a bit sneaky because of... quirks. `nodemon` recently added TypeScript support, but internally it simply runs the `ts-node` command instead of `node`. However, to avoid the dependency for those using regular JS, they didn't add `ts-node` to its dependencies. You could avoid this by installing it in the project with `npm i -D ts-node`, but I wanted these to work without installing anything. This can be solved with `nodemon`'s `--exec` option by compounding `npx` scripts:
    ```
    cd src/path/to
    npx -y nodemon -q --exec 'npx -y ts-node' ./example.ts
    ```

    HOWEVER, you can't directly do this with `runtimeArgs` in a launch config, because VSCode messes up the quotes. To hack around this


    The `runtimeExecutable` is `npx`, which allows running modules directly from `npm`.
  8. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -39,10 +39,10 @@ These launch configs will allow you to debug typescript files directly from VSCo
    ```

    ## Explanation
    The first one is pretty straightforward. If the file is `src/one/two/three.ts`, this is the equivalent of:
    The first one is pretty straightforward. If the file is `src/path/to/example.ts`, this is the equivalent of:
    ```
    cd src/one/two
    npx -y ts-node three.ts
    cd src/path/to
    npx -y ts-node example.ts
    ```
    It's better to use `cwd` in this way, as this allows for nested `tsconfig` files as may appear in a monorepo.

  9. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,12 @@ npx -y ts-node three.ts
    ```
    It's better to use `cwd` in this way, as this allows for nested `tsconfig` files as may appear in a monorepo.

    The second one had to be a bit sneaky. `nodemon` has TypeScript support, but
    The second one had to be a bit sneaky because of the way that `nodemon` works. They recently added TypeScript support, but internally it simply runs the `ts-node` command instead of `node`. However, to avoid the dependency for those using regular JS, they didn't add `ts-node` to its dependencies. You could avoid this by installing it in the project with `npm i -D ts-node`, but I wanted these to work without installing anything. This can be solved with `nodemon`'s `--exec` option by compounding `npx` scripts:
    ```
    ```



    The `runtimeExecutable` is `npx`, which allows running modules directly from `npm`.

  10. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # Debugging TypeScript in VSCode
    These launch configs will allow
    These launch configs will allow you to debug typescript files directly from VSCode. It will honor the `tsconfig` and resolve node modules properly. You do not need to install `ts-node` or `nodemon`, as everything is run using `npx`.

    ## Launch Config
    ```json
    @@ -38,6 +38,18 @@ These launch configs will allow
    }
    ```

    ## Explanation
    The first one is pretty straightforward. If the file is `src/one/two/three.ts`, this is the equivalent of:
    ```
    cd src/one/two
    npx -y ts-node three.ts
    ```
    It's better to use `cwd` in this way, as this allows for nested `tsconfig` files as may appear in a monorepo.

    The second one had to be a bit sneaky. `nodemon` has TypeScript support, but

    The `runtimeExecutable` is `npx`, which allows running modules directly from `npm`.

    ## Debug current file
    This launch config will run the current typescript file in the debugger. This does not require `ts-node` to be installed, as it runs through `npx`.
    ```jsonc
  11. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    # Debugging TypeScript in VSCode
    These launch configs will allow

    ## Launch Config
    ```json
  12. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 37 additions and 0 deletions.
    37 changes: 37 additions & 0 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,42 @@
    # Debugging TypeScript in VSCode

    ## Launch Config
    ```json
    {
    "configurations": [
    {
    "type": "node",
    "request": "launch",
    "name": "ts-node current file",
    "runtimeExecutable": "npx",
    "runtimeArgs": ["-y", "ts-node"],
    "program": "${file}",
    "cwd": "${fileDirname}",
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen"
    },
    {
    "type": "node",
    "request": "launch",
    "name": "watch current file",
    "runtimeExecutable": "npx",
    "runtimeArgs": [
    "-y",
    "nodemon",
    "-q",
    "--exec",
    "$(echo npx -y ts-node ${file})"
    ],
    "program": "${file}",
    "cwd": "${fileDirname}",
    "restart": true,
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen"
    },
    ],
    }
    ```

    ## Debug current file
    This launch config will run the current typescript file in the debugger. This does not require `ts-node` to be installed, as it runs through `npx`.
    ```jsonc
  13. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ This launch config will run the current typescript file in the debugger. This do
    ```

    # Live Reloads
    If you want live reloading, you can use the combination of `nodemon` and `ts-node`. Unfortunately, I havent found a way to do this without installing `ts-node` (see below). As in all cases, I strongly recommend adding it as a `devDependency` in your project rather than installing globally. Global installs are the source of the vast majority of "works on my machine" problems.
    If you want live reloading, you can use the combination of `nodemon` and `ts-node`. Unfortunately, I havent found a way to do this without installing `ts-node` (see below). As in all cases, I strongly recommend adding it as a `devDependency` in your project rather than installing globally.

    ```
    npm i -D ts-node
    @@ -36,7 +36,7 @@ Then you can use this configuration:
    "request": "launch",
    "name": "watch current file",
    "runtimeExecutable": "npx",
    "runtimeArgs": ["-y", "nodemon"],
    "runtimeArgs": ["-y", "nodemon", "-q"],
    "program": "${file}",
    "cwd": "${fileDirname}",
    "restart": true,
  14. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,8 @@ This launch config will run the current typescript file in the debugger. This do
    }
    ```

    If you want live reloading, you can use the combination of `nodemon` and `ts-node`. Unfortunately, I havent found a way to do this without installing `ts-node`. The reason for this is that `nodemon` doesn't declare `ts-node` as a dependency, so `npx` doesn't add it. As in all cases, I strongly recommend adding it as a `devDependency` in your project rather than installing globally. Global installs are the source of the vast majority of "works on my machine" problems.
    # Live Reloads
    If you want live reloading, you can use the combination of `nodemon` and `ts-node`. Unfortunately, I havent found a way to do this without installing `ts-node` (see below). As in all cases, I strongly recommend adding it as a `devDependency` in your project rather than installing globally. Global installs are the source of the vast majority of "works on my machine" problems.

    ```
    npm i -D ts-node
    @@ -44,4 +45,5 @@ Then you can use this configuration:
    },
    ],
    }
    ```
    ```

  15. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    This launch config will run the current typescript file in the VSCode debugger. This does not require `ts-node` to be installed, as it runs through `npx`.
    # Debugging TypeScript in VSCode

    ## Debug current file
    This launch config will run the current typescript file in the debugger. This does not require `ts-node` to be installed, as it runs through `npx`.
    ```jsonc
    {
    "configurations": [
    @@ -17,7 +20,7 @@ This launch config will run the current typescript file in the VSCode debugger.
    }
    ```

    If you want live reloading, you can use the combination of `nodemon` and `ts-node`. Unfortunately, I havent found a way to do this without adding `ts-node` as a dev dependency. The reason for this is that `nodemon` doesn't declare `ts-node` as a dependency, so `npx` doesn't add it.
    If you want live reloading, you can use the combination of `nodemon` and `ts-node`. Unfortunately, I havent found a way to do this without installing `ts-node`. The reason for this is that `nodemon` doesn't declare `ts-node` as a dependency, so `npx` doesn't add it. As in all cases, I strongly recommend adding it as a `devDependency` in your project rather than installing globally. Global installs are the source of the vast majority of "works on my machine" problems.

    ```
    npm i -D ts-node
  16. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 16 additions and 1 deletion.
    17 changes: 16 additions & 1 deletion vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -25,5 +25,20 @@ npm i -D ts-node

    Then you can use this configuration:
    ```jsonc

    {
    "configurations": [
    {
    "type": "node",
    "request": "launch",
    "name": "watch current file",
    "runtimeExecutable": "npx",
    "runtimeArgs": ["-y", "nodemon"],
    "program": "${file}",
    "cwd": "${fileDirname}",
    "restart": true,
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen"
    },
    ],
    }
    ```
  17. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    This launch config will run the current typescript file in the VSCode debugger. This does not require `ts-node` to be installed, as it runs through `npx`.
    ```json
    ```jsonc
    {
    "configurations": [
    {
    @@ -17,4 +17,13 @@ This launch config will run the current typescript file in the VSCode debugger.
    }
    ```

    If you want live reloading, you can use the combination of `nodemon` and `ts-node`. Unfortunately, I havent found a way to do this without adding `ts-node` as a dev dependency.
    If you want live reloading, you can use the combination of `nodemon` and `ts-node`. Unfortunately, I havent found a way to do this without adding `ts-node` as a dev dependency. The reason for this is that `nodemon` doesn't declare `ts-node` as a dependency, so `npx` doesn't add it.

    ```
    npm i -D ts-node
    ```

    Then you can use this configuration:
    ```jsonc

    ```
  18. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    The following will run the typescript file currently opened in debug mode. This does not require `ts-node` to be installed, as it runs through `npx`.
    This launch config will run the current typescript file in the VSCode debugger. This does not require `ts-node` to be installed, as it runs through `npx`.
    ```json
    {
    "configurations": [
    @@ -17,4 +17,4 @@ The following will run the typescript file currently opened in debug mode. This
    }
    ```

    If you want live reloading
    If you want live reloading, you can use the combination of `nodemon` and `ts-node`. Unfortunately, I havent found a way to do this without adding `ts-node` as a dev dependency.
  19. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 18 additions and 1 deletion.
    19 changes: 18 additions & 1 deletion vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,20 @@
    The following will run the typescript file currently opened in debug mode. This does not require `ts-node` to be installed, as it runs through `npx`.
    ```json
    {
    "configurations": [
    {
    "type": "node",
    "request": "launch",
    "name": "ts-node current file",
    "runtimeExecutable": "npx",
    "runtimeArgs": ["-y", "ts-node"],
    "program": "${file}",
    "cwd": "${fileDirname}",
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen",
    },
    ],
    }
    ```

    ```
    If you want live reloading
  20. @ehaynes99 ehaynes99 revised this gist Jul 31, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,3 @@
    ‎‎​
    ```json

    ```
  21. @ehaynes99 ehaynes99 created this gist Jul 31, 2022.
    1 change: 1 addition & 0 deletions vscode-debug-current.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ‎‎​