使用最新版本的Firebase和节点v10在VSCode中本地调试Firebase函数

问题描述 投票:0回答:1

[Web上似乎有很多@google-cloud/functions-emulator的示例,但现在已弃用。我浏览了最新的firebase文档Test functions interactively,在这里我们可以使用Shell在本地测试功能。

我尝试使用VSCode进行调试,但是每当我按下调试器按钮时,VSCode都会向我发出此警告,然后立即停止调试:

C:\Program Files\nodejs\node.exe --inspect-brk=46655 functions\lib\index.js 
Debugger listening on ws://127.0.0.1:46655/c8545176-06c0-4b95-80ec-bcba4ca9d90e
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail
setup.js:53 

我也用ts / js代码初始化了管理对象,但是调试器也出现了同样的问题:

 const admin = require("firebase-admin");
if (!admin.apps.length)
    admin.initializeApp({
        projectId: "...",
        appId: "...",
        databaseURL: "...",
        storageBucket: "...",
        apiKey: "...",
        authDomain: "...",
        messagingSenderId: "...",
        measurementId: "..."
    });

VSCode launch.json

"version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "skipFiles": ["<node_internals>/**"],
      "program": "${file}",
      "outFiles": ["${workspaceFolder}/**/*.js"]
    }
  ]

firebase函数package.json

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "10"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^8.6.0",
    "firebase-functions": "^3.3.0"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.1.6",
    "tslint": "^5.20.1",
    "typescript": "^3.7.2"
  },
  "private": true
}

firebase.json:

{
  "hosting": {
    "public": "_site",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "functions": {
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run lint",
        "npm --prefix \"$RESOURCE_DIR\" run build"
      ]
    },
    "rewrites": [
      {
        "source": "/bigben",
        "function": "bigben"
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ],
    "cleanUrls": true
  }
}

平台:Windows 10节点:v10项目:具有Typescript功能的Firebase Web应用

firebase:7.8.1。

我想知道是否有可能在VSCode中放置断点并运行调试器以获取最新的Firebase函数。

firebase debugging visual-studio-code localhost google-cloud-functions
1个回答
0
投票

Firebase CLI中的仿真器当前不支持此功能,但是正在使用该功能。您可以在这里阅读:

https://github.com/firebase/firebase-tools/issues/1360

© www.soinside.com 2019 - 2024. All rights reserved.