firebase / firebase-functions

Firebase SDK for Cloud Functions
https://firebase.google.com/docs/functions/
MIT License
1.01k stars 201 forks source link

Deployment Error: Function with scheduler failed with "timezone is invalid" #1504

Closed avivdaniel closed 5 months ago

avivdaniel commented 6 months ago

Description:

index.js file :

const functions = require("firebase-functions");
const firestore = require("@google-cloud/firestore");
const client = new firestore.v1.FirestoreAdminClient();

const bucket = "gs://MY_BUCKET_NAME_HERE";

exports.scheduledFirestoreExport = functions.pubsub
    .schedule("every 7 days")
    .onRun((context) => {
      const projectId = process.env.GCP_PROJECT;
      const databaseName = client.databasePath(projectId, "(default)");

      return client.exportDocuments({
        name: databaseName,
        outputUriPrefix: bucket,
        collectionIds: [],
      })
          .then((responses) => {
            const response = responses[0];
            console.log(`Operation Name: ${response["name"]}`);
          })
          .catch((err) => {
            console.error(err);
            throw new Error("Export operation failed");
          });
    });

package.json file:


{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "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": "14"
  },
  "main": "index.js",
  "dependencies": {
    "@google-cloud/firestore": "^7.1.0",
    "firebase-admin": "^12.0.0",
    "firebase-functions": "^4.5.0"
  },
  "devDependencies": {
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

Deployment Error: When running firebase deploy --only functions, encountering the following error about timezone :

Screenshot 2023-12-17 at 16 38 44

Error on google cloud console that may be related `Function failed on loading user code. This is likely due to a bug in the user code. Error message: Provided module can't be loaded. Did you list all required modules in the package.json dependencies? Detailed stack trace: Error: Cannot find module 'firebase-admin/auth' Require stack:

Can anyone face the same problem?

google-oss-bot commented 6 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

exaby73 commented 5 months ago

Hello @avivdaniel. From your screenshot, you are deploying to us-central1 but your project seems to be in one of the Europe regions. Could you set your region to the correct region using setGlobalOptions? See Change a function's region or regions

avivdaniel commented 5 months ago

Hello @avivdaniel. From your screenshot, you are deploying to us-central1 but your project seems to be in one of the Europe regions. Could you set your region to the correct region using setGlobalOptions? See Change a function's region or regions

Yes you are right :) that was the issue. Thanks!

exaby73 commented 5 months ago

Glad you got it working. I feel safe closing this issue. Feel free to comment and I can reopen the issue if you disagree