Firebase CloudScheduler GCLOUD_PROJECT错误

时间:2019-12-06 20:36:04

标签: node.js firebase google-cloud-platform google-cloud-scheduler

这是我的功能,顶部是配置,底部是功能

const functions = require('firebase-functions')
const Stripe = require('stripe')

const axios = require('axios')
const admin = require('firebase-admin')
const serviceAccount = require('./serviceAccountKey.json')

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: 'https://c6dcc.firebaseio.com'
})

exports.detectConnect = functions.pubsub
 .topic('detectConnect')
 .onPublish(async message => {
    console.log('THIS THING RAN')
    return null
 })

这些是我的依赖项

"dependencies": {
    "@google-cloud/storage": "^2.0.0",
    "axios": "^0.19.0",
    "child-process-promise": "^2.2.1",
    "firebase-admin": "~7.0.0",
    "firebase-functions": "^2.2.0",
    "mkdirp": "^0.5.1",
    "mkdirp-promise": "^5.0.1",
    "node-fetch": "^2.6.0",
    "request": "^2.88.0",
    "stripe": "^7.1.0"
},

但是firebase抛出错误

Error: process.env.GCLOUD_PROJECT is not set.
at TopicBuilder (/srv/functions/node_modules/firebase-functions/lib/providers/pubsub.js:43:19)
at cloudFunctionNewSignature (/srv/functions/node_modules/firebase-functions/lib/cloud-functions.js:102:13)
at cloudFunction (/srv/functions/node_modules/firebase-functions/lib/cloud-functions.js:151:20)
at Promise.resolve.then (/srv/node_modules/@google-cloud/functions-framework/build/src/invoker.js:330:28)
at process._tickCallback (internal/process/next_tick.js:68:7)

使用schedule-functions

时也会出现错误

1 个答案:

答案 0 :(得分:2)

如果您正在运行Node 10,请确保您使用的是最新版本的firebase-tools,并确保使用Firebase CLI进行部署。从节点10开始,GCLOUD_PROJECT环境变量默认不再可用。

如果仍然遇到问题,请尝试将package.json中的Node引擎更改为"8",看看是否有更多的成功。