node.js - 无法在 Visual Studio Code 中调试无服务器应用程序

标签 node.js visual-studio-code serverless-framework serverless-architecture

我尝试在 VS 代码中调试使用无服务器框架开发的无服务器应用程序。我关注了this文章。

但是当我尝试调试代码时,我从 VS 代码中得到一个错误,如下所示。

无法启动程序 'g:\Projects\Serverless1\node_modules.bin\sls';设置“outDir 或 outFiles”属性可能会有所帮助。

文件夹中已经存在sls命令文件,下面是launch.json文件设置

"version": "0.2.0",
"configurations": [

    {
        "type": "node",
        "request": "launch",
        "protocol": "inspector",
        "name": "run hello function",
        "program": "${workspaceRoot}\\node_modules\\.bin\\sls",
        "args": [
            "invoke",
            "local",
            "-f",
            "hello",
            "--data",
            "{}"
        ]

    }
]

请帮我解决这个问题。

最佳答案

我试图关注 the same article ,并遇到同样的错误。添加 outFiles 并没有帮助,尽管它 确实 将我的错误消息更改为:

Cannot launch program 'd:\<path>\node_modules\.bin\sls' because corresponding JavaScript cannot be found.

我无法解释为什么 VSCode 在 node_modules/.bin 中的可执行文件有问题,但如果我指向 node_modules/serverless/bin,一切正常正如预期的那样:

"program": "${workspaceFolder}\\node_modules\\serverless\\bin\\serverless",

这是我的完整工作配置,我的测试事件 JSON 存在于项目根目录的 sample-event.json 中:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Debug Lambda",
            "program": "${workspaceFolder}/node_modules/serverless/bin/serverless",
            "args": [
                "invoke",
                "local",
                "-f",
                "<function-name>",
                "--data",
                "{}" // You can use this argument to pass data to the function to help with the debug
            ]
        }
    ]
}

使用无服务器 ^1.26.1、Node 8.9.4 LTS、VSCode 1.20.1

关于node.js - 无法在 Visual Studio Code 中调试无服务器应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45437205/

相关文章:

node.js - VSCODE 构建错误 `The terminal process "/bin/zsh '-c' , 'yarn run watch-extensionsd' "无法启动(退出代码 : 127). `

visual-studio-code - 如何在VSCode扩展中创建BrowserWindow

amazon-web-services - 将 Lambda 函数分配给 serverless.yml 中的特定 VPC ID

node.js - 如何在环回 4 mongoDB 中使模型属性唯一?

javascript - 代码覆盖率显示 if-branch 丢失,但删除它会导致错误

JSON 对象未定义 (Nodejs)

amazon-web-services - 属性投影不能为空

javascript - 我正在尝试将纬度和经度保存到 Mongoose 模型,但我无法存储它们

visual-studio-code - Visual Studio代码: Disable quote wrapping text selection

amazon-web-services - 无服务器框架 - 新变量解析器