简体   繁体   English

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

[英]Can't debug serverless app in Visual Studio Code

I'm trying to find out how can I use Visual Studio Code debugger to debug serverless lambda function. 我试图找出如何使用Visual Studio Code调试器来调试无服务器的lambda函数。 For testing purposes I have very simple test lambda function: 出于测试目的,我有非常简单的test lambda函数:

module.exports.handler = async (event) => {
  debugger;
  console.log(111, event);
};

Then, in launch.json I created such a configuration: 然后,在launch.json我创建了这样一个配置:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch via NPM",
            "runtimeVersion": "8.4.0",
            "runtimeExecutable": "node",
            "program": "${workspaceFolder}/node_modules/.bin/sls",
            "cwd": "${workspaceRoot}",
            "args": [
                "invoke",
                "local",
                "--function",
                "test",
                "--data",
                "{foo:'bar'}"
            ],
            "port": 9229
        }
    ]
 }

Now, I'm puting a breakpoint inside my lambda function and pressing F5 to start debugger. 现在,我在lambda函数中放置一个断点并按F5启动调试器。 I'm expecting then to go in code, put some watches and walk my code step-by-step. 我期待着进入代码,放一些手表,一步一步地走我的代码。 But nothing happens. 但没有任何反应。 No errors. 没有错误。 No console outputs, no code paused on breakpoints. 没有控制台输出,断点上没有代码暂停。 Nothing. 没有。 All I get is message in debug console : /home/set/.nvm/versions/node/v8.4.0/bin/node node_modules/.bin/sls invoke local --function test --data {foo:'bar'} 我得到的只是debug console消息: /home/set/.nvm/versions/node/v8.4.0/bin/node node_modules/.bin/sls invoke local --function test --data {foo:'bar'}

If I go then in terminal and run that line I got exactly what is expected 如果我去终端然后运行那条线路,我就得到了预期的结果

set@set-home ~/www/blahblah/ens $ /home/set/.nvm/versions/node/v8.4.0/bin/node node_modules/.bin/sls invoke local --function test --data {foo:'bar'}
Serverless: INVOKING INVOKE
111 '{foo:bar}'

What am I doing wrong? 我究竟做错了什么? How can I debug serverless application in Visual Studio Code? 如何在Visual Studio代码中调试无服务器应用程序?

I suspect you just need to get rid of the "port": 9229 bit. 我怀疑你只需要摆脱"port": 9229位。

I've never specified a port for debugging Serverless functions locally, but adding it to any of my working configurations produces the symptoms you observe. 我从未在本地指定用于调试无服务器功能的端口,但将其添加到我的任何工作配置会产生您观察到的症状。


Incidentally, you might be able to take some of the other stuff out, as well. 顺便说一下,你也可以把其他一些东西拿走。 For reference, my Serverless debug configurations typically look like this for invoking locally: 作为参考,我的无服务器调试配置通常看起来像本地调用:

    {
        "type": "node",
        "request": "launch",
        "name": "Debug sls local",
        "program": "${workspaceFolder}/node_modules/serverless/bin/serverless",
        "args": [
            "invoke", "local", "--function", "processFirehose", "--path", "sample-event.json",
            "--stage",
            "nonprod",
        ]
    },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 Visual Studio Code 中调试无服务器应用程序 - Cannot debug serverless application in Visual Studio Code 如何使用无服务器捆绑包在无服务器框架项目中调试 Visual Studio Code 中的测试? - How can I debug tests in Visual Studio Code with a serverless-framework project using the serverless-bundle package? 如何使用另一个端口在 Visual Studio Code 中调试无服务器脱机? - How to debug Serverless Offline in Visual Studio Code using another port? 无法使用 Visual Studio Code 调试 Azure JavaScript Function - Can't Debug Azure JavaScript Function using Visual Studio Code 如何在Visual Studio Code中调试TypeScript Express应用 - How to debug TypeScript Express app in Visual Studio Code 如何在 Visual Studio 代码中调试 nodeJS (ExpressJS) 应用程序? - How to debug nodeJS (ExpressJS) app in visual studio code? 如何在 Visual Studio 代码中调试“create-react-app”? - How to debug `create-react-app`s in visual studio code? 在 Visual Studio 代码中调试不起作用 - Debug in visual studio code is not working 我无法在 Visual Studio Code 中使用 `node app.js` 命令 - I can't use the `node app.js` command in Visual Studio Code Visual Studio Code 无法调试 Electron - Visual Studio Code unable to debug Electron
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM