Cannot debug serverless application in Visual Studio Code

I tried to debug a serverless application developed using a serverless environment in VS code. I followed this article.

But when I try to debug the code, I get an error message from the VS code, as shown below.

Cannot start program 'g: \ Projects \ Serverless1 \ node_modules.bin \ sls'; setting the attribute 'outDir or outFiles' may help.

The sls command file already exists in the folder and the following launch.json file parameters

"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", "{}" ] } ] 

Please help me solve this problem.

+10
source share
3 answers

I tried to follow the same article and experienced the same error. Adding outFiles did not help, although it changed my error message to:

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

I cannot explain why VSCode has a problem with the executable in node_modules/.bin , but if I instead node_modules/serverless/bin on node_modules/serverless/bin , everything will work as expected:

 "program": "${workspaceFolder}\\node_modules\\serverless\\bin\\serverless", 

Here is my full working configuration, where my test JSON event exists in sample-event.json in the root of the project:

 { "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 ] } ] } 

Using Serverless ^ 1.26.1, Node 8.9.4 LTS, VSCode 1.20.1

+17
source

To get debugging to work with TypeScript, I needed to add outFiles to the folder where my code was compiled.

 "outFiles": [ "${workspaceRoot}/dist/**/*.js" ] 

I did not try to debug direct JS, but I would suggest that it is something like this.

 "outFiles": [ "${workspaceRoot}/**/*.js" ] 
+1
source

None of the solutions worked for me, so here is my modification as a resource. In addition, several employees were able to attack by simply enabling the auto-join feature and using the local invoke keywords.

Below is a snippet of the launch.json file that ultimately helped me. / w comments for clarity where my function is called Processor.

--function or -f The name of the function in your service that you want to call locally.

--path or -p The path to the json file containing the input that will be passed to the called function as an event. This path refers to the root directory of the service.

--stage or -s The stage in your service where you want to call your function.

  • "without server": "^ 1.30.3"
  • "serverless -p lugin-typcript": "^ 1.1.5",
  • node: 8.10.0
  • npm: 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 } ] } 
0
source

Source: https://habr.com/ru/post/1270428/


All Articles