属性“程序”不存在 - VS代码中的错误

问题描述 投票:0回答:1

所以我创建了一个名为“Node Projects”的新文件夹,并将其添加到VS Code上的“Workspace”。然后我创建了两个名为“test.js”和“test2.js”的示例文件。在这些文件中,我只需要一个日志命令来确定哪个正在运行。

当我运行test.js时,我收到错误消息“属性'程序'不存在(C:\ Users \ MyName \ Documents \ NodeProjects / Node Projects / test.js',所以我点击”打开launch.json“按钮,看到这个:

{
    // 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"
        }
    ]
}

基于我在stackoverflow上的搜索,我相信问题在于“程序”行,所以我继续将其更改为

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

所以现在,当我做一个F5时,调试器会运行test.js,这很棒。但是因为test.js值是硬编码的,即使我在编辑器上打开test2.js并执行F5,它也会再次运行test.js!所以我尝试从launch.json中删除文件名(即test.js)。但是现在当我尝试运行文件时,我收到“无法启动程序”的错误。哦,并删除launch.json也没有帮助(它只是重新创建了初始的launch.json文件,我回到了原点)。

node.js visual-studio-code
1个回答
5
投票

试试这个, “program”:“$ {file}”

$ {file}是当前打开文件的VS Code中的预定义变量。见https://code.visualstudio.com/docs/editor/variables-reference

© www.soinside.com 2019 - 2024. All rights reserved.