无法在Visual Studio代码中调试无服务器应用程序

Wel*_*lla 11 node.js visual-studio-code serverless-framework serverless-architecture

我试图在VS代码中调试使用无服务器框架开发的无服务器应用程序.我已经听过这篇文章了.

但是当我尝试调试代码时,我从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",
            "{}"
        ]

    }
]
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题.

Mik*_*ick 22

我试图遵循同一篇文章,并遇到了同样的错误.添加outFiles没有帮助,虽然它确实将我的错误消息更改为:

Cannot launch program 'd:\<path>\node_modules\.bin\sls' because corresponding JavaScript cannot be found.
Run Code Online (Sandbox Code Playgroud)

我无法解释为什么VSCode存在可执行文件的问题node_modules/.bin,但如果我指向node_modules/serverless/bin,则事情按预期工作:

"program": "${workspaceFolder}\\node_modules\\serverless\\bin\\serverless",
Run Code Online (Sandbox Code Playgroud)

这是我的完整工作配置,我的测试事件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
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

使用无服务器^ 1.26.1,节点8.9.4 LTS,VSCode 1.20.1


小智 2

为了使用 TypeScript 进行调试,我需要将outFilesset 添加到编译代码所在的文件夹中。

"outFiles": [
    "${workspaceRoot}/dist/**/*.js"
]
Run Code Online (Sandbox Code Playgroud)

我没有尝试过直接调试 JS,但我认为它是这样的。

"outFiles": [
    "${workspaceRoot}/**/*.js"
]
Run Code Online (Sandbox Code Playgroud)