我尝试在 VS 代码中调试使用无服务器框架开发的无服务器应用程序。我关注了this文章。
但是当我尝试调试代码时,我从 VS 代码中得到一个错误,如下所示。
无法启动程序 'g:\Projects\Serverless1\node_modules.bin\sls';设置“outDir 或 outFiles”属性可能会有所帮助。
文件夹中已经存在sls命令文件,下面是launch.json文件设置
"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",
"{}"
]
}
]
请帮我解决这个问题。
最佳答案
我试图关注 the same article ,并遇到同样的错误。添加 outFiles
并没有帮助,尽管它 确实 将我的错误消息更改为:
Cannot launch program 'd:\<path>\node_modules\.bin\sls' because corresponding JavaScript cannot be found.
我无法解释为什么 VSCode 在 node_modules/.bin
中的可执行文件有问题,但如果我指向 node_modules/serverless/bin
,一切正常正如预期的那样:
"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、Node 8.9.4 LTS、VSCode 1.20.1
关于node.js - 无法在 Visual Studio Code 中调试无服务器应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45437205/