Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode launch.json to debug node project within subfolder

I have a node project as a subfolder within my main project. I am trying to create a launch config for VS Code so that it starts debugging index.ts file when I open the parent folder. Here's what my folder structure looks like: Folder structure

So my node project is in the subfolder called NodeBackend. I want to press F5 or THE GREEN BUTTON on VS Code and start debugging my typescript file.

When I do that from within the parent folder I get an error:

Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

However, I can debug it without issues when I load the "NodeBackend" project in VS code and press F5 or THE GREEN BUTTON.

My launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "cwd": "${workspaceFolder}\\NodeBackend",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}\\NodeBackend\\src\\index.ts",
            "outFiles": [
                "${workspaceFolder}/**/*.js"
            ]
        }
    ]
}

Here's my source code: https://github.com/Kayes-Islam/SimpleProject

like image 218
Kayes Avatar asked Apr 09 '26 22:04

Kayes


1 Answers

Here is my launch.json for a similar project structure:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Debug Express",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "cwd": "${workspaceFolder}\\backend",
            "program": "${workspaceFolder}\\backend\\src\\app.ts",
            "runtimeArgs": [
                "-r",
                "ts-node/register",
                "-r",
                "tsconfig-paths/register"
            ],
            "outFiles": [
                "${workspaceFolder}/**/*.js"
            ],
        }
    ]
}

The above configuration works though the console display the following errors:

C:\Program Files\nodejs\node.exe -r ts-node/register -r tsconfig-paths/register .\src\app.ts
Could not read source map for file:///C:/Users/path/to/project/backend/node_modules/typescript/lib/typescript.js: ENOENT: no such file or directory, open 'c:\Users\path\to\project\backend\node_modules\typescript\lib\typescript.js.map'
(node:23068) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

Hope that can help. Cheers,

like image 165
dirtwan Avatar answered Apr 12 '26 16:04

dirtwan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!