无法在 Visual Studio Code 中调试无服务器应用程序 [英] Cannot debug serverless application in Visual Studio Code
问题描述
我尝试在 VS 代码中调试使用无服务器框架开发的无服务器应用程序.我遵循了 这篇 文章.
I have tried to debug serverless application developed using serverless framework in VS code. I have followed this article.
但是当我尝试调试代码时,我从 VS 代码中收到一个错误,如下所示.
But when I trying to debug the code I'm getting an error from VS code as below.
无法启动程序g:\Projects\Serverless1\node_modules.bin\sls";设置outDir 或 outFiles"属性可能会有所帮助.
Cannot launch program 'g:\Projects\Serverless1\node_modules.bin\sls'; setting the 'outDir or outFiles' attribute might help.
文件夹中已存在sls命令文件,以下是launch.json文件设置
sls command file already exists in the folder and following are the launch.json file settings
"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",
"{}"
]
}
]
请帮我解决这个问题.
推荐答案
我试图关注 同一篇文章,遇到了同样的错误.添加 outFiles
没有帮助,尽管它确实将我的错误消息更改为:
I attempted to follow the same article, and experienced the same error. Adding outFiles
didn't help, although it did change my error message to:
Cannot launch program 'd:\<path>\node_modules\.bin\sls' because corresponding JavaScript cannot be found.
<小时>
我无法解释为什么 VSCode 在 node_modules/.bin
中的可执行文件有问题,但如果我指向 node_modules/serverless/bin
,事情就会正常运行正如预期的那样:
I can't explain why VSCode has a problem with the executable in node_modules/.bin
, but if I point at node_modules/serverless/bin
instead, things work as expected:
"program": "${workspaceFolder}\\node_modules\\serverless\\bin\\serverless",
<小时>
这是我的完整工作配置,我的测试事件 JSON 存在于项目根目录的 sample-event.json
中:
{
"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
]
}
]
}
<小时>
使用无服务器 ^1.26.1、节点 8.9.4 LTS、VSCode 1.20.1
Using Serverless ^1.26.1, Node 8.9.4 LTS, VSCode 1.20.1
这篇关于无法在 Visual Studio Code 中调试无服务器应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!