无法在Visual Studio代码中debugging无服务器应用程序
我曾尝试debugging在VS代码中使用无服务器框架开发的无服务器应用程序。 我跟着这篇文章。
但是当我试图debugging代码时,我得到了如下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", "{}" ] } ]
请帮我解决这个问题。
要debugging以使用TypeScript我需要添加outFiles
设置到我的编译代码所在的文件夹。
"outFiles": [ "${workspaceRoot}/dist/**/*.js" ]
我没有试图debugging直JS,但我会认为这是这样的。
"outFiles": [ "${workspaceRoot}/**/*.js" ]
我试图按照相同的文章 ,并经历了同样的错误。 添加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",
这是我完整的工作configuration,其中我的testing事件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", "--function", "<function-name>", "--path", "sample-event.json" ] } ] }
使用无服务器1.24.1,节点9.1.0,VSCode 1.18.1