0

There seem to be many examples for @google-cloud/functions-emulator on the web but this has become deprecated now. I went through latest firebase docs Test functions interactively where we can test the functions locally using shell.

I tried debugging in VSCode but whenever I hit the debugger button, VSCode gives me this warning and then halt debugging immediately:

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 

I also initialized the admin object in ts/js code but debugger gave the same issue:

 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 functions 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
  }
}

Platform: Windows 10
Node: v10
Project: Firebase web app with Typescript functions

firebase: 7.8.1.

I wonder if it's all possible to put breakpoints and run the debugger in VSCode for latest firebase functions.

Community
  • 1
  • 1
GorvGoyl
  • 42,508
  • 29
  • 229
  • 225

1 Answers1

1

It's not currently supported by the emulators in the Firebase CLI, but the feature is being worked on. You can read about it here:

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

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441