所以我知道这个问题已经被问了很多,常见的答案是添加一个这样的区域:
export.webhookEurope = functions
.region('europe-west1')
.https.onRequest((req, res) => {
res.send("Hello");
});
但在我的情况下,我使用的是onCreate方法,在函数中对上述代码进行采样只会导致错误。代码如下所示。
export const onCreate = functions.firestore
.document('parent/{id}')
.region('europe-west1')
.onCreate(async (snapshot, context) => {
// some code which deploys correctly if I leave out the 'region'
});
因此,在没有"区域"部分的情况下进行部署很好,但如果我保留它,它会给我以下错误:
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions@ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Error: functions predeploy error: Command terminated with non-zero exit code2
那么,更改默认区域的正确方法是什么呢?
您将对region()
的调用放在生成器的错误部分。它出现在您触发的产品的识别之前:
export const onCreate = functions
.region('europe-west1')
.firestore
.document('parent/{id}')
.onCreate(async (snapshot, context) => {
// some code which deploys correctly if I leave out the 'region'
});
API参考资料将来可能会有所帮助。尤其是FunctionBuilder。