5

我试图调试使用VS代码中无服务器框架开发的无服务器应用程序。我跟着this文章。无法在Visual Studio中调试无服务器应用程序代码

但是当我试图调试代码时,我收到了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", 
      "{}" 
     ] 

    } 
] 

请帮我解决这个问题。

+0

面对完全一样的问题。它在控制台上工作,但不通过调试配置。如果您找到解决方案,请让我知道。 –

回答

0

要调试使用TypeScript我需要将outFiles设置添加到我的编译代码所在的文件夹。

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

我还没有尝试调试直JS,但我会认为它是这样的。

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

我已经尝试添加outFiles,但仍然得到相同的错误。它与此无关并且VS代码在发生任何其他错误时总会给出此错误。 设置'outDir或outFiles'属性可能会有所帮助。 – Wella

2

我试图按照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", 

这里是我的全部工作配置,在我的TES牛逼事件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

+1

工作就像一个魅力。 –

+0

谢谢!正在把我的头发拉出来。 – MungeWrath

相关问题