最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Node Debug serverless offline using vscode - Stack Overflow

programmeradmin1浏览0评论

I am using VS Code for development of AWS Lambda functions, I started using the serverless framework and the serverless offline library but, I am unable to use VS Code's debug mode to locally debug the code.

I am referring many sites, Following is one of them: /@OneMuppet_/debugging-lambada-functions-locally-in-vscode-with-actual-break-points-deee6235f590

My project structure is as follows:

Package.json:

launch.json:

I get the following error when I start debug:

Can someone please guide, with the correct configuration?

I am using VS Code for development of AWS Lambda functions, I started using the serverless framework and the serverless offline library but, I am unable to use VS Code's debug mode to locally debug the code.

I am referring many sites, Following is one of them: https://medium.com/@OneMuppet_/debugging-lambada-functions-locally-in-vscode-with-actual-break-points-deee6235f590

My project structure is as follows:

Package.json:

launch.json:

I get the following error when I start debug:

Can someone please guide, with the correct configuration?

Share Improve this question edited Oct 28, 2019 at 5:17 marc_s 755k184 gold badges1.4k silver badges1.5k bronze badges asked Apr 29, 2019 at 4:53 Dev1ceDev1ce 5,94424 gold badges98 silver badges160 bronze badges 3
  • what does your launch.json config look like? – joeCarpenter Commented May 1, 2019 at 19:58
  • @joeCarpenter updated the question with launch.json – Dev1ce Commented May 2, 2019 at 2:53
  • Thank you Aniruddha. Still not able to get it going – joeCarpenter Commented May 2, 2019 at 12:44
Add a comment  | 

3 Answers 3

Reset to default 11

in the package.json add debug script:

"scripts": {
.......
    "debug": "node --inspect node_modules/serverless/bin/serverless offline -s dev",
.........
}

VS code lunch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "name": "Serverless",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run",
        "debug"
      ],
      "port": 9229
    }
  ]
}

Then start debugging from VS code

The warning you are seeing is a deprecation warning; the legacy debugger (--debug) has been deprecated since Node 7.7.0. The correct way to attach a node debugger to serverless offline is by using --inspect:

node --inspect $(npm bin)/sls offline start

If you have a valid sample event in JSON format AND you are OK with debugging one function at a time, then here is a configuration that has worked great for me. It enables breakpoints and step-through debuggin exactly as you'd expect:

    {
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "name": "sls invoke local: myFunction",
      "runtimeExecutable": "sls",
      "runtimeArgs": [
        "invoke",
        "local",
        "-f",
        "loadOptions",
        "-p",
        "activities/myFunction/myFunction-event.json"
      ],
    },
发布评论

评论列表(0)

  1. 暂无评论