After setting up an AWS Lambda using the serverless framework template, I encountered an issue when trying to debug/troubleshoot this lambda in my local environment. Despite successfully running a basic 'hello' function locally, I faced an error when attempting to set breakpoints for debugging.
[offline] Loading handler... (/Users/mickey/vault/github/backend-work/merlin-lambdas/be-ts-sponsored/.build/.webpack/service/src/functions/hello/handler)
[offline] _____ HANDLER RESOLVED _____
offline: Failure: Cannot find module '/Users/mickey/vault/github/backend-work/merlin-lambdas/be-ts-sponsored/.build/.webpack/service/src/functions/hello/handler'
Require stack:
- /Users/mickey/vault/github/backend-work/merlin-lambdas/be-ts-sponsored/node_modules/serverless-offline/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js
I am now seeking advice on how to effectively trace/debug this lambda, particularly since it is configured with webpack. Do I need to remove webpack for debugging purposes, or is there a way to work around it?
Your insights and assistance are highly appreciated.
Note: Relevant sections from my vcode launch.json and package.json files are provided below:
vcode launch.json:
{
"type": "node",
"request": "launch",
"name": "DEBUG",
"runtimeExecutable": "npm",
"cwd": "${workspaceRoot}",
"runtimeArgs": [
"run-script",
"debug"
],
"console": "integratedTerminal",
"restart": true,
"internalConsoleOptions": "neverOpen",
"port": 9229
}
package.json script samples:
"scripts": {
"start": "serverless offline -s dev",
"build": "yarn tsc",
"tsc": "tsc --project tsconfig.json",
"debug": "export SLS_DEBUG=* && node --inspect ./node_modules/.bin/serverless offline -s dev",
"test": "echo \"Error: no test specified\" && exit 1"
}