0

In my vscode app I have a folder called apiEngine/

In this folder is my node app.

Why does it not debug in vscode?

enter image description here

enter image description here

.vscode\launch.json


{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Build Project",
            "program": "${workspaceFolder}\\apiEngine\\src\\index.ts",
            "preLaunchTask": "npm: build",
            "sourceMaps": true,
            "smartStep": true,
            "internalConsoleOptions": "openOnSessionStart",
            "outFiles": [
                "${workspaceFolder}/apiEngine/dist/**/*.js"
            ]
        }
    ]
}

.vscode\tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "npm",
            "script": "build",
            "path": "apiEngine/",
            "group": "build",
            "problemMatcher": []
        },
        {
            "type": "typescript",
            "tsconfig": "apiEngine/tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ],
            "group": "build"
        }
    ]
}

1 Answer 1

2

If you set "preLaunchTask": "npm: build", VS code expects an npm script build inside package.json in your workspace root (directory containing your .vscode folder). It does not want to execute your build task in .vscode\tasks.json.

That is also the reason, why you get the error - package.json resides one level deeper inside apiEngine folder, so VS Code cannot find the script inside workspace root.

Solution

In order to invoke the IDE task instead, you can specify a label for your build task and set this label instead of npm: build in preLaunchTask. The task's path argument will provide the proper package.json location.

.vscode\tasks.json:

tasks: [
  {
    label: "npm-build",
    type: "npm",
    script: "build",
    path: "apiEngine/",
    group: "build",
    problemMatcher: []
  },
  ...
];

.vscode\launch.json:

...
// before: 
// "preLaunchTask": "npm: build"
// after:
"preLaunchTask": "npm-build", 
...
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.