繁体   English   中英

Firebase-tools 没有将新创建的函数上传到 Firebase

[英]Firebase-tools is not uploading newly created functions to Firebase

我正在开发一个 Angular 项目,我正在编写 Firebase 函数,我想将这些函数部署到 Firebase。 当我为 Firebase 编写更多函数并尝试使用firebase deploy --only functions将它们部署到 Firebase 时,只有现有的函数会被部署。 更具体地说,我有 16 个功能要部署到 Firebase,但只有相同的 12 个被部署。

到目前为止,我已经做了以下尝试来解决这个问题:

  1. 我确保我使用的是最新的 firebase-tools (6.7.0)
  2. 我已经尝试使用firebase deploy --only functions:<NEW FUNCTION NAME HERE>
  3. 从 functions/src/index.ts 文件中删除所有导出函数并上传一个空白 index.ts。 即使使用空白 index.ts 文件,相同的功能仍会部署到 Firebase。
  4. 我知道将函数上传到 Firebase 时可能会有长达 30 秒的延迟,所以我什至等了一整晚才尝试上传新函数。
  5. 我已经使用firebase init从头开始重新创建整个函数目录,它仍然不断上传相同的函数。
  6. 我从免费的 Firebase 计划升级到 Spark 计划。

以下代码是位于 functions/src/index.ts 中的主要 index.ts 文件。

import * as functions from 'firebase-functions';
import { firestore } from 'firebase-admin';
import * as moment from 'moment';
import { request } from 'https';

// Local Functions Imports
import * as Permissions from './permissions';
import * as Groups from './groups';
import * as Shifts from './shifts';
import * as Roles from './roles';
import * as Session from './sessions';
import * as Users from './users';
import * as Slack from './slack';
import * as ScheduleChanges from './schedule-changes';
import * as Email from './email';

// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

/* -------- USER MANAGEMENT -------------- */
export const createUser = Users.createUser;
export const addUserToDefaultJoinGroups = Users.addUserToDefaultJoinGroups;
export const deleteUser = Users.deleteUser;

/* -------- SESSION MANAGEMENT -------------- */
export const addSessionID = Session.addSessionID;

/* -------- ROLE MANAGEMENT -------------- */
export const addRoleID = Roles.addRoleID;
export const removeAllShiftsAssociatedWithRole = Roles.removeAllShiftsAssociatedWithRole;

/* -------- SHIFT MANAGEMENT -------------- */
export const addShiftID = Shifts.addShiftID;
export const hourly_job = Shifts.hourly_job;
export const changeShiftStatsTest = Shifts.changeShiftStatsTest;

/* -------- GROUPS MANAGEMENT -------------- */
export const addGroupID = Groups.addGroupID;
export const addGroupIDNewTestFunction = Groups.addGroupIDNewTestFunction;

/* -------- PERMISSIONS MANAGEMENT -------------- */
export const addPermissionID = Permissions.addPermissionID;

/* -------- Emailing -------------- */
export const sendWelcomeEmailToNewUser = Email.sendWelcomeEmailToNewUser;
export const sendWelcomeEmailToNewUser2 = Email.sendWelcomeEmailToNewUser2;

/* -------- SLACK MESSAGING MANAGEMENT -------------- */
export const sendWelcomingMessage = Slack.sendWelcomingMessage;

/* -------- SCHEDULE CHANGES MANAGEMENT -------------- */
export const addScheduleChangeID = ScheduleChanges.addScheduleChangeID;

从上面的代码中可以看出,有 16 个函数应该部署到 Firebase。 但是,只有 12 个被部署。 以下代码片段来自functions/src/groups/index.ts。 在这个文件中,addGroupID 是一个现有的 function,它会不断地部署到 Firebase。 另一方面, addGroupIDNewTestFunction 是一个新的 function ,即使它们在同一个文件中并且以相同的方式引用,也没有部署到 Firebase 。

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin'

export const addGroupID = functions.firestore
.document("organizations/{organizationID}/groups/{groupID}")
.onCreate(async (snap, context) => {
    console.log("Adding group id");
    await admin.firestore()
    .doc(`organizations/${context.params.organizationID}/groups/${context.params.groupID}`).update({
        'groupID': context.params.groupID
    })
})

export const addGroupIDNewTestFunction = functions.firestore
.document("organizations/{organizationID}/groups2/{groupID}")
.onCreate(async (snap, context) => {
    console.log("Adding group id");
    await admin.firestore()
    .doc(`organizations/${context.params.organizationID}/groups/${context.params.groupID}`).update({
        'groupID': context.params.groupID
    })
})

如前所述,我在主 index.ts 文件中指定了 16 个函数,这些函数应该部署到 Firebase 函数中。 但是,只有现有的 12 个功能正在部署。 以下代码片段是 output firebase 在我运行firebase deploy --only functions时给我的。

firebase deploy --only functions

=== Deploying to 'university-scheduling'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions
> tslint --project tsconfig.json

no-unused-variable is deprecated. Since TypeScript 2.9. Please use the built-in compiler checks instead.

Could not find implementations for the following rules specified in the configuration:
    use-input-property-decorator
    use-output-property-decorator
    use-host-property-decorator
Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed.
If TSLint was recently upgraded, you may have old rules configured which need to be cleaned up.


WARNING: /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions/src/email/index.ts:2:13 - 'admin' is declared but its value is never read.
WARNING: /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions/src/index.ts:2:1 - All imports on this line are unused.
WARNING: /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions/src/index.ts:3:13 - 'moment' is declared but its value is never read.
WARNING: /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions/src/index.ts:4:1 - All imports on this line are unused.
WARNING: /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions/src/slack/index.ts:2:13 - 'admin' is declared but its value is never read.
WARNING: /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions/src/slack/index.ts:6:7 - 'request' is declared but its value is never read.
WARNING: /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions/src/slack/index.ts:7:7 - 'options' is declared but its value is never read.
WARNING: /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions/src/users/index.ts:3:1 - All imports on this line are unused.
WARNING: /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions/src/users/index.ts:43:11 - 'groups' is declared but itsvalue is never read.
WARNING: /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions/src/users/index.ts:65:11 - 'uid' is declared but its value is never read.

Running command: npm --prefix "$RESOURCE_DIR" run build

> functions@ build /Users/brandon/Dropbox/Bearforce_Scheduling/bearforce-website/functions
> tsc

✔  functions: Finished running predeploy script.
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (106.24 KB) for uploading
✔  functions: functions folder uploaded successfully
⚠  appEngineLocation us-central1
i  functions: updating Node.js 6 function createUser(us-central1)...
i  functions: updating Node.js 6 function deleteUser(us-central1)...
i  functions: updating Node.js 6 function addSessionID(us-central1)...
i  functions: updating Node.js 6 function addRoleID(us-central1)...
i  functions: updating Node.js 6 function removeAllShiftsAssociatedWithRole(us-central1)...
i  functions: updating Node.js 6 function addShiftID(us-central1)...
i  functions: updating Node.js 6 function hourly_job(us-central1)...
i  functions: updating Node.js 6 function changeShiftStatsTest(us-central1)...
i  functions: updating Node.js 6 function addGroupID(us-central1)...
i  functions: updating Node.js 6 function addPermissionID(us-central1)...
i  functions: updating Node.js 6 function sendWelcomingMessage(us-central1)...
i  functions: updating Node.js 6 function addScheduleChangeID(us-central1)...
✔  scheduler: all necessary APIs are enabled
✔  functions[addPermissionID(us-central1)]: Successful update operation.
✔  functions[createUser(us-central1)]: Successful update operation.
✔  functions[addShiftID(us-central1)]: Successful update operation.
✔  functions[changeShiftStatsTest(us-central1)]: Successful update operation.
✔  functions[sendWelcomingMessage(us-central1)]: Successful update operation.
✔  functions[hourly_job(us-central1)]: Successful update operation.
✔  functions[addSessionID(us-central1)]: Successful update operation.
✔  functions[deleteUser(us-central1)]: Successful update operation.
✔  functions[addGroupID(us-central1)]: Successful update operation.
✔  functions[removeAllShiftsAssociatedWithRole(us-central1)]: Successful update operation.
✔  functions[addScheduleChangeID(us-central1)]: Successful update operation.
✔  functions[addRoleID(us-central1)]: Successful update operation.

✔  Deploy complete!

Please note that it can take up to 30 seconds for your updated functions to propagate.

您应该检查编译 js 文件的目录。

默认值为functions/lib/

如果你在functions/srcfunctions/src/tests等的任何地方导入../../foo.ts ,那么编译后的 js 文件是functions/lib/{any}/foo.js

部署目标文件仅为functions/lib/*.js 因此, functions/lib/{any}/foo.js被忽略。

您应该更改目录或文件结构。

如果原因是测试文件,那么您应该使用tsconfig.json进行部署并排除它们。

我想向你们提供有关我上述问题的解决方案的最新信息。 在我的一个 index.ts 文件中,我有以下 require 语句,var mailgun = require('mailgun-js')。 每当我将这个 require 语句替换为 import * as mailgun from 'mailgun-js' 时,所有功能都已正确部署。

关于整个问题最令人困惑的部分是,即使事情没有正常工作,我也只收到成功消息。 我非常感谢你们的快速支持和所有建议!!

我遇到了完全相同的问题,解决方案是编辑 functions/src/index.ts 而不是 functions/lib/index.js

就我而言,它是 index.ts,因为我在使用“firebase init”初始化项目时选择了该选项,您的情况取决于它,也可以是 index.js,但始终在 /src 中而不是在 /lib 中。

我认为 /lib 文件夹如果用于编译文件。

部署函数时,编译器会将 src/ .ts 文件转换为“lib/src/ .js”文件。 不知何故,我在“lib/*js”空间中从以前的部署中得到了一些文件。 果然,这些文件正在部署,但包含我创建的新 function 的文件位于“lib/src/*js”中。没有新的更改被传递到云函数中。

所以我进入了 package.json 并改变了

"main": "lib/index.js",

读书

"main": "lib/src/index.js",

为了清理,我从“lib/”中删除了 all.js 文件

我回来做生意了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM