Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attribute 'Program' does not exist - error in VS Code

So I have created a new folder called "Node Projects" and I added it to "Workspace" on VS Code. I then created two sample files called "test.js" and "test2.js". In these files I simply have a single log command to determine which is running.

When I run the test.js, I get the error message "Attribute 'program' does not exist (C:\Users\MyName\Documents\NodeProjects/Node Projects/test.js' so I click on "Open launch.json" button and see this:

{
    // 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": "Launch Program",
            "program": "${workspaceFolder}/Node Projects\\test.js"
        }
    ]
}

Based on my search here on stackoverflow, I believe the problem is with the "program" line, so I go ahead and change it to

"program": "${workspaceFolder}\\test.js"

So now, when I do a F5, the debugger runs the test.js which is great. But because the test.js value is hard-coded, even when I open test2.js on the editor and do an F5, it runs test.js again! So I tried removing the file name (i.e. test.js) from launch.json. But now when I try to run a file, I get the error that "Cannot launch program". Oh and deleting the launch.json didnt help either (it just recreated the initial launch.json file and I was back to square one).

like image 788
houman_ag Avatar asked Sep 09 '26 10:09

houman_ag


2 Answers

Try this,
"program": "${file}"

${file} is a predefined variable in VS Code for the current opened file. See https://code.visualstudio.com/docs/editor/variables-reference

like image 135
JD Pavek Avatar answered Sep 11 '26 01:09

JD Pavek


Add another key "cwd", and it works for me.

    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/xxx/xxx.js",
            "cwd": "${workspaceFolder}"
        }
    ]
like image 35
Yosef Avatar answered Sep 11 '26 03:09

Yosef



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!