Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing for VSCode debugger #589

Closed
GorvGoyl opened this issue Nov 27, 2019 · 2 comments

Comments

@GorvGoyl
Copy link

Looking at the related old git issues I thought that problem was fixed in node v10 but it's not! at least in my case.
I want to debug firebase functions locally in VSCode (breakpoints) 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 followed the guide https://firebase.google.com/docs/functions/local-shell to set GOOGLE_APPLICATION_CREDENTIALS but that seem to have no affect. This config works for firebase functions:shell but not for vscode debugger.

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"]
    }
  ]

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
Project: Firebase web app with Typescript functions

firebase versions are mentioned in above json.

Do let me know if further details are required.

@google-oss-bot
Copy link
Collaborator

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@mbleigh
Copy link
Contributor

mbleigh commented Dec 10, 2019

I'm not that familiar with the VS Code debugger but it looks like it's just running the code directly without wrapping it in the Firebase CLI commands that typically provide those environment variables. You should be able to mimic the CLI behavior by setting up your debugger to launch with FIREBASE_CONFIG env variable set to a JSON serialization of your Firebase Admin SDK config (see https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects/getAdminSdkConfig for what should go in there).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants