Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 无法在Visual Studio代码中调试无服务器应用程序_Node.js_Visual Studio Code_Serverless Framework_Serverless Architecture - Fatal编程技术网

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

Node.js 无法在Visual Studio代码中调试无服务器应用程序,node.js,visual-studio-code,serverless-framework,serverless-architecture,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":

我曾尝试在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",
            "{}"
        ]

    }
]

请帮助我解决此问题。

要调试TypeScript,我需要将
outFiles
集添加到编译代码所在的文件夹中

"outFiles": [
    "${workspaceRoot}/dist/**/*.js"
]
我没有试着调试straight JS,但我会假设它是这样的

"outFiles": [
    "${workspaceRoot}/**/*.js"
]
我试图跟随,并经历了同样的错误。添加
outFiles
没有帮助,尽管它确实将我的错误消息更改为:

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

这是我的完整工作配置,其中我的测试事件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
            ]
        }
    ]
}
{
“版本”:“0.2.0”,
“配置”:[
{
“类型”:“节点”,
“请求”:“启动”,
“名称”:“调试Lambda”,
“程序”:“${workspaceFolder}/node_modules/serverless/bin/serverless”,
“args”:[
“调用”,
“本地”,
“-f”,
"",
“--数据”,
“{}”//您可以使用此参数将数据传递给函数以帮助调试
]
}
]
}


使用Serverless ^1.26.1、Node 8.9.4 LTS、VSCode 1.20.1

没有一个解决方案适合我,因此这里是我作为资源所做的修改。此外,多个同事只需打开“自动附加”并使用“调用本地关键字”,就可以进行攻击

下面是launch.json的一个片段,它最终对我有用/为清楚起见,我的函数名为Processor

--function or-f服务中要在本地调用的函数的名称

--path或-p指向json文件的路径,该文件包含要作为事件传递给被调用函数的输入数据。此路径相对于服务的根目录

--stage or-s要在其中调用函数的服务中的stage

  • “无服务器”:“^1.30.3”
  • “无服务器插件类型脚本”:“^1.1.5”
  • 节点:8.10.0
  • 净现值:5.6.0

    {
      "version": "0.2.0",
      "configurations": [
          {
              "type": "node",
              "request": "launch",
              "name": "Debug Lambda",
              "program": "${workspaceFolder}/node_modules/.bin/sls",
              "args": [
                  "invoke",
                  "local",
                  "-f",
                  "Processor",
                  "-p",
                  "./events/S3toLambda.json",
                  "-s",
                  "local"
              ],
              "autoAttachChildProcesses": true
          }
      ]
    }
    
2020年更新: 按照其他指南中的说明进行操作,并使用
launch.json
文件设置项目

我遇到的问题是,假定的文件
“program”:“${workspaceRoot}/node\u modules/.bin/sls”
抛出了一个错误

我把它改成了
“${workspaceRoot}/node\u modules/serverless/bin/serverless”
,它成功了。以下是完整的文件:

.vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Serverless debug",
            "program": "${workspaceRoot}/node_modules/serverless/bin/serverless",
            "args": [
                "invoke",
                "local",
                "-f",
                "hello",
                "--data",
                "{}"
            ]
        }
    ]
}

请注意参数
hello
是我要调试的函数的名称。我认为预期的使用情形必须是,您为想要调用的任何函数更改该文件名。也许有人可以创建一个VSCode插件来实现这一点?

面对完全相同的问题。它是从控制台工作的,但不是通过调试配置。请让我知道,如果你找到一个解决方案。我已经尝试添加外文件,但仍然得到相同的错误。它与此无关,当发生任何其他错误时,VS代码总是给出此COMMO错误。设置“outDir或outFiles”属性可能会有所帮助。效果非常好。谢谢!在我的情况下,即使我指出了${workspaceRoot}/node\u/serverless/bin/serverless,并且该路径正确解析为实际的serverless模块的--save dev安装,VS代码也不会运行serverless,导致属性“program”不存在。然而,将程序更改为/Users/username/.nvm/versions/node/v8.10.0/bin/serverless确实有效。
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Serverless debug",
            "program": "${workspaceRoot}/node_modules/serverless/bin/serverless",
            "args": [
                "invoke",
                "local",
                "-f",
                "hello",
                "--data",
                "{}"
            ]
        }
    ]
}