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

相關問題