2

Context & Goal

Recently I joined a team that is developing a serverless Node.js webpack application with VSCode. My goal is to be able to run the application so that breakpoints are hit within Visual Studio Code.

Context

Judging from several articles/posts listed below, there are two configuration files that need to be adjusted in order to achieve this. The launch.json file that specifies what VSCode needs to do when you start debugging from the editor. And the package.json file and more specifically the scripts attribute. Unfortunately I am not able to make it work.

From the information I gathered, there is a difference between the configuration used for Linux and Windows machines. Since I am running on a Windows 10 machine, I did adjust several settings.

Used resources: article, post 1, post 2 and post 3

Problem

Below you will find the settings I have set. Unfortunately the application starts throwing exceptions almost immediately in several NPM modules. The first error message I receive is from the loader.js file and is No such module: constants. If I continue, several other errors are triggered. At the moment I am lost as to why these errors are caused, since the application with the normal configuration works without problems. Also I think the yarn debug seems to run fine, although I am not a 100% sure.

Question

In short I am completely lost as to what goes wrong. Any advice and pointers would be greatly appreciated.

Settings & Output

Before the error, the Debug Console does report that the debugger is attached and call the serverless commands afterwards.

Debugger listening on ws://127.0.0.1:5858/00a881f0-be74-46dd-a316-6fa07e8b0db5
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.

package.json scripts attribute

"scripts": {
    "debug": "SET SLS_DEBUG=* && node --inspect-brk=5858 %USERPROFILE%\\AppData\\Roaming\\npm\\node_modules\\serverless\\bin\\serverless offline -s dev",
  },

launch.json

"version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "node",
            "request": "launch",
            "cwd": "${workspaceRoot}\\frontend\\backend",
            "runtimeExecutable": "npm.cmd",
            "runtimeArgs": [
             "run-script",
             "debug"
            ],
            "port": 5858
           }
    ]
}

EDIT 1

I think the problem is that the debug script (see below) does not invoke serverless (offline). The terminal does not show serverless (offline) being run and that might explain why node is unsuccessful in building the solution. I adjusted the script to the following, but it is to no avail. For reference, I have included the script that is used to run it locally without debugging.

"scripts": {
    "serve": "cross-env SLS_DEBUG=* IS_LOCAL=true serverless offline --env local",
    "debug": "cross-env SET SLS_DEBUG=* && node --inspect-brk=5858 .\\node_modules\\serverless\\bin\\serverless offline -s dev --env local ",
  },
Fluous
  • 2,075
  • 2
  • 17
  • 29

0 Answers0