标签: firebase-cli

在 Github Actions 中部署 Firebase 会出现授权失败错误

我正在尝试使用 github 操作自动将 React 应用程序部署到 firebase,但出现以下错误:

Error: Autorization failed. This account is missing the following required permissions on project ***
 firebase.projects.get
 firebasehosting.sites.update
Run Code Online (Sandbox Code Playgroud)

我有多个站点,当我尝试使用它手动部署时,firebase deploy --only hosting:MY_SITE_NAME它工作正常。我的工作流程中有两份工作。构建作业通过,但部署作业失败。这是我的工作流程文件:

name: Build and Deploy to Firebase
on:
  push:
    branches:
      - master

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@master
      - name: Install Dependencies
        run: yarn install
      - name: Build
        run: yarn build
      - name: Archive Production Artifact
        uses: actions/upload-artifact@master
        with:
          name: build
          path: build
  deploy:
    name: Deploy …
Run Code Online (Sandbox Code Playgroud)

firebase firebase-cli github-actions

5
推荐指数
1
解决办法
8349
查看次数

如何在组和区域中部署单个 Firebase Cloud Function?

我创建了一组v2部署在区域 ( europe-west1) 中的 Firebase Cloud Functions ( )。

\n\n
#index.ts\nimport * as apiV2 from \'./v2\';\nexport const v2 = apiV2;\n
Run Code Online (Sandbox Code Playgroud)\n\n
#v2.ts\nexport const addTextMessage = functions.region(\'europe-west1\').onCall(\n ...\n)\n
Run Code Online (Sandbox Code Playgroud)\n\n

我只想部署该addTextMessage功能。\n我尝试过:

\n\n
#index.ts\nimport * as apiV2 from \'./v2\';\nexport const v2 = apiV2;\n
Run Code Online (Sandbox Code Playgroud)\n\n

但是该功能尚未部署:

\n\n
#v2.ts\nexport const addTextMessage = functions.region(\'europe-west1\').onCall(\n ...\n)\n
Run Code Online (Sandbox Code Playgroud)\n\n

我应该使用什么命令?

\n

firebase google-cloud-functions firebase-cli

5
推荐指数
1
解决办法
1968
查看次数

Firebase Firestore 适用于真实数据库,但不适用于模拟器

我正在使用 Firebase 并开始尝试使用 Firebase 模拟器运行本地开发实例。我正在运行 Firebase Tools v8.4.1。当我使用真正的 Firestore 数据库运行时,一切正常。然而,当我使用模拟器时,出现了一些问题。

我可以创建set一个文档,然后get通过 Javascript 进行处理,但 Firebase 模拟器 UI 中没有显示任何内容,反之亦然,当我通过 Firebase 模拟器 UI 添加数据时,它无法get在 Javascript 中使用。此外,当我使用 Firebase Tools CLI 的导入和导出功能时,我通过 Javascript 添加的任何数据都不会导出和导入。我在浏览器控制台中没有收到任何错误。

我不确定我在初始化 Firebase 或缺少的其他配置时是否有问题?

我在跑:firebase emulators:start --only functions,firestore

Firebase 设置代码

import * as firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
import 'firebase/functions';

const db = firebase.initializeApp({
  apiKey: 'my_api_key',
  appId: 'my_app_id',
  authDomain: 'my_auth_domain',
  databaseURL: 'my_database_url',
  messagingSenderId: 'my_messaging_sender_id',
  projectId: 'my_project_id',
  storageBucket: 'my_storage_bucket',
}).firestore();

if (process.env.NODE_ENV === 'development') …
Run Code Online (Sandbox Code Playgroud)

javascript firebase typescript google-cloud-firestore firebase-cli

5
推荐指数
1
解决办法
2266
查看次数

如何通过 github actions 部署 firebase 函数?

在我的项目中,其文件夹结构如下所示:

dev-internal-web
-.firebase
-.github
-e2e
-functions
-node_modules
-src
(misc files)
Run Code Online (Sandbox Code Playgroud)

我有一个函数文件夹,其中包含 firebase 函数。我希望通过我的操作脚本自动部署它,如下所示:

name: CI

on:
  push:
    branches:
    - master

jobs:
  hosting-deploy:
    name: Deploy Hosting
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@master
    - uses: actions/setup-node@master
      with:
        node-version: '10.x'
    - run: npm install
    - run: npm run build
    - uses: w9jds/firebase-action@master
      with:
        args: deploy --only hosting --project=tombstone-roleplay
      env:
        FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

  functions-deploy:
      name: Deploy Functions
      runs-on: ubuntu-latest

      steps:
      - uses: actions/checkout@master
      - uses: chrissank/deploy-firebase-functions@1.0.0
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
          TARGET: default …
Run Code Online (Sandbox Code Playgroud)

npm firebase google-cloud-functions firebase-cli github-actions

5
推荐指数
1
解决办法
3007
查看次数

在多个项目中使用 Firebase Emulator Suite

我通常使用针对 Web 应用程序、管理门户和云功能的单独存储库来组织我的 Firebase 项目。因为 Web 应用程序和管理门户使用相同的 firebase 项目,所以我将云功能保留在自己单独的存储库中。因此,3 个不同的存储库/项目使用同一个 Firebase 项目。

我正在测试如何通过此设置使用 Firebase 本地模拟器套件,但似乎无法在我的 Cloud Function 项目中启动云函数的模拟器,然后在我的 Web 应用程序项目中使用模拟器进行 firestore 和调用这些函数,然后对我的经理门户项目进行同样的操作。这将导致冲突并导致它们全部在不同的端口上运行,并且函数项目将无法访问 firestore 模拟器,并且 Web 应用程序和管理器将无法访问函数模拟器。

有办法让这项工作发挥作用吗?我能看到的唯一方法是将我的管理器应用程序、网络应用程序和功能全部放在同一个项目/存储库中……出于多种原因,我不想这样做。

目前,我刚刚在 firebase 上建立了第二个 Staging 项目并使用它进行测试,但希望能够在本地完成所有这些工作。任何帮助深表感谢。

firebase firebase-cli

5
推荐指数
1
解决办法
1783
查看次数

Firebase 函数 - FirebaseError:在非交互模式下运行时缺少必需的选项(强制)

我有一个 Firebase 函数,当用户的帐户被删除时,它会删除 Firestore 数据库中用户的集合。

const firebase_tools = require("firebase-tools");
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();

exports.deleteUser = functions.auth.user().onDelete((user) => {
  return firebase_tools.firestore
      .delete(`users/${user.uid}`, {
        project: process.env.GCLOUD_PROJECT,
        token: functions.config().fb.token,
        recursive: true,
        yes: true
      }).catch((error) => {
        console.log(error);
        throw new functions.https.HttpsError(
            "unknown",
            "Error deleting user's data"
        );
      });
});
Run Code Online (Sandbox Code Playgroud)

每当删除用户并执行该函数时,我都会在函数日志中收到以下错误。

FirebaseError: Missing required options (force) while running in non-interactive mode
    at prompt (/workspace/node_modules/firebase-tools/lib/prompt.js:16:15)
    at promptOnce (/workspace/node_modules/firebase-tools/lib/prompt.js:29:11)
    at Command.actionFn (/workspace/node_modules/firebase-tools/lib/commands/firestore-delete.js:69:51)
    at Object.delete (/workspace/node_modules/firebase-tools/lib/command.js:190:25)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Run Code Online (Sandbox Code Playgroud)

我能找到的与此相关的唯一信息是有关将功能部署/删除到 Firebase 的信息,并且我找不到太多有关 firebase-tools …

node.js firebase google-cloud-functions google-cloud-firestore firebase-cli

5
推荐指数
2
解决办法
1199
查看次数

Firebase 函数部署问题(无法创建/更新函数)

想请熟悉Firebase功能的人帮忙。我正在努力解决通过 firebase cli 上传代码失败的问题。几天前它就可以工作了,我没有改变任何东西,我的意思是通过配置。它被困在甚至没有进行代码更改的部分。自从客户将编辑者角色设置为所有者角色以来,我就遇到了这个问题。但理论上这不应该是一个问题。

firebase deploy --debug返回这个:

{"error":{"code":403,"message":"Unable to retrieve the repository metadata for projects/{projectname}/locations/us-central1/repositories/gcf-artifacts. Ensure that the Cloud Functions service account has 'artifactregistry.repositories.list' and 'artifactregistry.repositories.get' permissions. You can add the permissions by granting the role 'roles/artifactregistry.reader'.","status":"PERMISSION_DENIED"}}
Run Code Online (Sandbox Code Playgroud)

我设置了但是还是不行。也许是在错误的地方或者我不知道。我只在网上遇到过类似的问题,但都没有帮助。我不知道该怎么办。Artifactregistry api 也已启用。

firebase 功能:日志:

2022-11-09T22:15:55.891760Z E friendRequestNotification: {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":7,"message":"Unable to retrieve the repository metadata for projects/{projectname}/locations/us-central1/repositories/gcf-artifacts. Ensure that the Cloud Functions service account has 'artifactregistry.repositories.list' and 'artifactregistry.repositories.get' permissions. You can add the permissions by granting the role 'roles/artifactregistry.reader'."},"authenticationInfo":{"principalEmail":"{email}"},"requestMetadata":{"callerIp":"{ip}","callerSuppliedUserAgent":"FirebaseCLI/11.16.0,gzip(gfe),gzip(gfe)","requestAttributes":{"time":"2022-11-09T22:15:56.055987Z","auth":{}},"destinationAttributes":{}},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.CreateFunction","authorizationInfo":[{"resource":"projects/{projectname}/locations/us-central1/functions/friendRequestNotification","permission":"cloudfunctions.functions.create","granted":true,"authorizationLoggingOptions":{"permissionType":"ADMIN_WRITE"},"resourceAttributes":{}}],"resourceName":"projects/{projectname}/locations/us-central1/functions/friendRequestNotification","request":{"function":{"sourceUploadUrl":"https://storage.googleapis.com/uploads-760418412171.us-central1.cloudfunctions.appspot.com/6d1f7217-7899-484f-911c-1dbcb4512d8d.zip?GoogleAccessId=service-{}@gcf-admin-robot.iam.gserviceaccount.com&Expires={}","labels":{"deployment-tool":"cli-firebase","firebase-functions-hash":"{hash}"},"runtime":"nodejs16","dockerRegistry":"ARTIFACT_REGISTRY","entryPoint":"friendRequestNotification","name":"projects/{projectname}/locations/us-central1/functions/friendRequestNotification","eventTrigger":{"eventType":"providers/cloud.firestore/eventTypes/document.create","resource":"projects/{projectname}/databases/(default)/documents/users/{userId}/friends/{friendId}"}},"location":"projects/{projectname}/locations/us-central1","@type":"type.googleapis.com/google.cloud.functions.v1.CreateFunctionRequest"},"resourceLocation":{"currentLocations":["us-central1"]}}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了 Google 云 iam&admin …

function firebase google-cloud-functions firebase-cli

5
推荐指数
3
解决办法
2556
查看次数

Firebase CLI服务无法从其他设备访问项目

我已经安装了firebase cli etcetc。我可以启动项目并使用FirebaseServ开发。我可以通过localhost:5000访问项目页面,但是如果我尝试从网络(移动电话)中的其他设备访问network-ip:5000,则连接会被拒绝。

任何人都知道转发端口5000需要什么配置/命令?(像creat-react-app这样的不同项目效果很好)

firebase firebase-cli

4
推荐指数
1
解决办法
2085
查看次数

Firebase功能部署,但未在控制台中显示

这个问题与问题44799104基本相同,只是我提供了我的index.js(唯一的答案没有帮助,因为我包括'exports').

简而言之,我已经成功部署了我的功能,

控制台输出

但它没有显示在控制台中.我哪里错了?这是我的index.js:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);

var delayInMilliseconds = 5000;


exports.copyRoom= functions.database.ref('/RoomsOwn/${AuthUid}').onWrite((event) => {

    var uid = event.params.AuthUid;
    console.log('AuthID: ' + uid);
    var object = event.data.val();
    console.log('Whole Object: ', object);

    setTimeout(function() {
    return admin.database.ref('/RoomsOthers/${uid}').set(object);
    }, delayInMilliseconds);

  });
Run Code Online (Sandbox Code Playgroud)

javascript firebase google-cloud-functions firebase-cli

4
推荐指数
1
解决办法
1731
查看次数

Cloud Functions部署失败:“函数在加载用户代码时失败。错误消息:无法加载文件lib / index.js中的代码。”

我将firebase-functions模块升级到3.0.1。现在,当我部署云功能时,会收到警告消息:

?功能:不建议将功能部署到Node 6运行时。节点8可用并且是推荐的运行时。

然后,部署因以下原因而失败:

Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/node_modules/firebase-functions/lib/providers/https.js:282
    const func = async (req, res) => {
                       ^

SyntaxError: Unexpected token (
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/index.js:39:15)
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

firebase google-cloud-functions firebase-cli

4
推荐指数
1
解决办法
1288
查看次数