我一直在尝试部署名为onFollowUser
的firebase函数,但是它一直无法启动。我目前有Blaze计划,这是错误消息:
⚠ functions[onFollowUser(us-central1)]: Deployment error.
Failed to configure trigger providers/cloud.firestore/eventTypes/document.create@firestore.googleapis.com (__gcf__.us-central1.onFollowUser)
Functions deploy had errors with the following functions:
onFollowUser
To try redeploying those functions, run:
firebase deploy --only functions:onFollowUser
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
这是我完整的index.js
:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.onFollowUser =
functions
.firestore
.document('/Followers/{userID}/User Follower/{followerID}')
.onCreate(async (snapshot, context) => {
console.log(snapshot.data());
});
我发现了错误...我的数据库位于欧洲中部,但是由于某种原因,它正在部署到美国中部...我该如何更改?它说要部署到的项目的ID是正确的。
这是我的package.json:
{
"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": "10"
},
"dependencies": {
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1"
},
"devDependencies": {
"eslint": "^5.12.0",
"eslint-plugin-promise": "^4.0.1",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
答案 0 :(得分:2)
这是一个已知问题,请参阅:Error Deploying Firestore Function with a space in the name of a collection
重命名a集合,使它们不包含空格,而是使用驼峰式大小写,破折号或下划线。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
admin.firestore().settings({ timestampsInSnapshots: true });
exports.onFollowUser =
functions
.firestore
.document('/Followers/{userID}/User-Follower/{followerID}')
.onCreate(async (snapshot, context) => {
console.log(snapshot.data());
return;
});