aldobsom
aldobsom

Reputation: 2531

Firebase Functions and external node packages

In ./functions/index.js I have required a couple of external packages (node_modules) like: jsonwebtoken, uuid or escapeHtml but they do not work as in the browser I get:

"Error: could not handle the request"

questions: how can I make it work?

./functions/index.js:

const functions = require("firebase-functions");
const jwt = require("jsonwebtoken");

exports.getToken = functions.https.onRequest(async (request, response) => {
  const token = await jwt.sign({ id: 3333 }, "secret");
  response.send("Hello from Firebase! + ", token);
});

PS: In the documentations it says it's suppose to allow external packages even local packages https://firebase.google.com/docs/functions/handle-dependencies

package.json:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "dependencies": {
    "firebase-admin": "^8.9.0",
    "firebase-functions": "^3.3.0",
    "jsonwebtoken": "^8.5.1",
    "uuid": "^8.1.0"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.1.6"
  },
  "private": true
}

Upvotes: 0

Views: 216

Answers (1)

aldobsom
aldobsom

Reputation: 2531

Looking through the http://console.firebase.google.com dashboard I found out that in the functions/logs there is this error:

Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions

I think this means that with a free firebase account (Spark) it will not allow me to run external node_packages. But probably this would work with a Pay as you go plan (Blaze).

Can someone with a Blaze plan please confirm that external node packages work with firebase in their functions/index.js file?

Upvotes: 1

Related Questions