我正在做一个 Angular 项目,我正在编写我想部署到 Firebase 的 Firebase 函数。当我为 Firebase 编写更多函数并尝试使用firebase deploy --only functions
将它们部署到 Firebase 时,只会部署现有函数。更具体地说,我想将 16 个函数部署到 Firebase,但只部署了相同的 12 个。
到目前为止,我已经执行以下操作来尝试解决问题:
我- 确保我使用的是最新的火力基础工具(6.7.0)
- 我尝试使用
firebase deploy --only functions:<NEW FUNCTION NAME HERE>
指定我想部署的新编写的函数 - 从 functions/src/index.ts 文件中删除所有导出函数,并上传一个空白的 index.ts。即使使用空白的index.ts文件,相同的功能仍会部署到Firebase。
- 我知道将函数上传到 Firebase 时可能会有长达 30 秒的延迟,所以我甚至在尝试上传新功能之前等了一整晚。 我已经从头开始使用
firebase init
重新创建整个函数目录,它仍然不断上传相同的函数。- 我从免费的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 是一个现有函数,会不断部署到 Firebase。另一方面,addGroupIDNewTestFunction是一个新功能,即使它们在同一个文件中并以相同的方式被引用,也不会部署到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
})
})
如前所述,我在 main index.ts 文件中指定了 16 个函数,这些函数应该部署到 Firebase 函数中。但是,只有现有的 12 个功能正在部署。以下代码片段是我在 Angular 项目中运行firebase deploy --only functions
时 firebase 给我的输出。
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/src
或functions/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')。每当我用 import * 替换这个 require 语句作为来自 'mailgun-js' 的 mailgun 时,所有函数都得到了正确部署。
关于整个问题最令人困惑的部分是,即使事情无法正常工作,我也只收到成功消息。我非常感谢你们的快速支持和所有建议!!
我遇到了完全相同的问题,解决方案是编辑functions/src/index.ts而不是functions/lib/index.js
就我而言,它是 index.ts,因为我在使用"firebase init"初始化项目时选择了该选项,您的情况取决于它,也可以是索引.js但始终在/src 上而不是在/lib 上。
我认为/lib 文件夹如果用于编译文件。
部署函数时,编译器将 src/.ts 文件转换为 "lib/src/.js" 文件。 不知何故,我在"lib/*js"空间中有一些来自以前部署的文件。果然,这些文件正在部署,但包含我创建的新功能的文件位于"lib/src/*js"中。没有新的更改传递到云函数中。
所以我进入了package.json并改变了
"main": "lib/index.js",
阅读
"main": "lib/src/index.js",
为了清理,我从"lib/"中删除了所有.js文件
我又开始营业了。