firebase使用VS Code附加调试器

Teo*_*ahi 6 firebase visual-studio-code google-cloud-functions

我正在使用firebase serve --only functions,hosting命令在本地运行模拟器.这很好用.但我想采取进一步措施,并希望在调试器附加的情况下在本地调试我的函数.网址示例:http:// localhost:5001/foo-project/us-central1/helloWorld

有可能这样做吗?

如何构建launch.json以将调试器附加到我的函数中?

   {
      "type": "node",
      "request": "attach",
      "name": "Attach",
      "port": 9229
    }
Run Code Online (Sandbox Code Playgroud)

Mat*_*son -1

像这样设置你的 launch.json :

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceFolder}/functions/index.js",
      "env": { "FIREBASE_CONFIG": "{\"databaseURL\":\"https://XXXXX-2d371.firebaseio.com\",\"storageBucket\":\"XXXXX-2d371.appspot.com\",\"projectId\":\"XXXX-2d371\"}"}
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

确保将“程序”设置为函数目录的起点。