VSCode调试器弄乱了相对路径

Owe*_*n M 4 javascript debugging npm visual-studio-code

所以我试图运行VSCode调试器运行我的express程序,但是我注意到它弄乱了相对目录路径。

当使用诸如JIMPNode图像操纵器之类的模块时,当我从Powershell运行应用程序时,我需要输入相对于项目根目录的路径(“ package.JSONis” 所在的位置)以查找图像。但是,当我从VSCode调试器运行它时,出现一个错误,因为它正在查找相对于我的app目录的图像,该目录是我的项目根目录中的一个文件夹。

有可以修改的配置可以解决此问题吗?

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"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

jsconfig.js

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "allowSyntheticDefaultImports": true
    },
    "exclude": [
        "node_modules"
    ]
}
Run Code Online (Sandbox Code Playgroud)

提前致谢

Owe*_*n M 8

解决了:

您需要包括"cwd": "${workspaceRoot}"在您的launch.json

  • “变量 ${workspaceRoot} 已被弃用,取而代之的是 ${workspaceFolder},以更好地与多根工作区支持保持一致。” - [文档](https://code.visualstudio.com/docs/editor/variables-reference#_why-isnt-workspaceroot-documented) (5认同)