Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Attribute 'program' does not exist" for basic node.js project

I created simple node.js application (source code from here https://azure.microsoft.com/en-us/blog/visual-studio-code-and-azure-app-service-a-perfect-fit/)

var http = require('http');
http.createServer(function (req, res) {
    console.log('Got request for ' + req.url);
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end('<h1>Hello Code and Azure Web Apps!</h1>');
}).listen(process.env.PORT);

And clicked VSCode generated launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}/app.js",
            "stopOnEntry": false,
            "args": [],
            "cwd": "${workspaceRoot}",
            "preLaunchTask": null,
            "runtimeExecutable": null,
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "NODE_ENV": "development"
            },
            "externalConsole": false,
            "sourceMaps": false,
            "outDir": null
        },
        {
            "name": "Attach",
            "type": "node",
            "request": "attach",
            "port": 5858,
            "address": "localhost",
            "restart": false,
            "sourceMaps": false,
            "outDir": null,
            "localRoot": "${workspaceRoot}",
            "remoteRoot": null
        }
    ]
}

And still when launched I see:

Attribute 'program' does not exist.

Can anybody help what's wrong?

like image 953
Valeriy Avatar asked May 22 '16 16:05

Valeriy


4 Answers

I believe that you need ${workspaceRoot}/server.js, not ${workspaceRoot}/app.js for program. The code you're using doesn't have an app.js, that's what that (poorly worded) error is telling you.

like image 138
mdickin Avatar answered Nov 08 '22 08:11

mdickin


I also encountered this issue because of where VS Code put the .vscode directory containing the launch.json file. It put it up one directory so I had to add the directory to the path as defined in the launch.json file:

"program": "${workspaceRoot}/myDir/app.js",

I hope this helps.

like image 31
Colin Avatar answered Nov 08 '22 08:11

Colin


Another issue I ran into is a path was configured Using\\Backslashes\\Like\\So and worked fine on Windows, but on Mac it gave the above error.

(Solution: changed to /)

like image 14
ripper234 Avatar answered Nov 08 '22 08:11

ripper234


The error is saying that the path to your code was wrong.

VSCode defines the parent directory of its configuration file ".vscode/launch.json" as "${workspaceRoot}" or "${workspaceFolder}".

So, for example, if you want to run file "myproject/subfolder/main.js", you should configure your "myproject/.vscode/launch.json" as follows: "program": "${workspaceRoot}/subfolder/main.js"

Note that configuring "program": "${workspaceRoot}/myproject/subfolder/main.js" is a mistake and will cause error "Attribute 'program' does not exist".

like image 4
user3179473 Avatar answered Nov 08 '22 09:11

user3179473