Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode debugger messing up relative paths

So I'm trying to run the VSCode debugger run my express program, but I noticed that it's messing up the relative directory paths.

When using a module like JIMP, a Node image manipulator, when I run the app from the Powershell, I need to enter the path relative to the project root (where the package.JSON is) to find the image. But when I run it from the VSCode debugger, I get an error, because it is finding the image relative to my app directory, which is a folder in my project root.

Is there a configuration I can edit to fix this?

launch.json :

{
    // Use IntelliSense to learn about possible Node.js debug 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": "npm start",
            "program": "${workspaceRoot}/app/app.js"
        }
    ]
}

jsconfig.js :

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "allowSyntheticDefaultImports": true
    },
    "exclude": [
        "node_modules"
    ]
}

Thanks in advance

like image 652
Owen M Avatar asked Mar 25 '17 16:03

Owen M


People also ask

How do you set a relative path in Visual Studio code?

Relative Path Extension for VS CodePress Ctrl+Shift+H (Mac: Cmd+Shift+H ) and start typing the file you want.

How do I change the debugging environment in vscode?

Alternatively, you can run your configuration through the Command Palette (Ctrl+Shift+P) by filtering on Debug: Select and Start Debugging or typing 'debug ' and selecting the configuration you want to debug. In addition, the debug status appears in the Status Bar showing the active debug configuration.

How do I copy a relative path in vscode?

In the visual studio code, it has commands to Copy Path and Copy Relative Path (Ctrl+Shift+p->File: Copy Path of Active File).


1 Answers

Solved it:

You need to include "cwd": "${workspaceRoot}" in your launch.json

like image 95
Owen M Avatar answered Oct 06 '22 23:10

Owen M