类型错误:升级到节点 10 后,无法读取 Firebase 函数中未定义的属性“名称”

Var*_*pta 5 javascript firebase google-cloud-functions

我最近收到警告,说 Node 8 已被 Cloud Functions for Firebase 弃用。我更新到节点 10,但随后我甚至在调用该函数并且未执行该函数之前就开始收到此错误。在恢复到节点 8 时修复了问题。我不确定如何调试此问题以获取更多信息。

TypeError: Cannot read property 'name' of undefined
    at dataConstructor (/workspace/node_modules/firebase-functions/lib/providers/database.js:137:85)
    at cloudFunctionNewSignature (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:119:34)
    at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:151:20)
    at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:198:28)
    at process._tickCallback (internal/process/next_tick.js:68:7) 
Run Code Online (Sandbox Code Playgroud)

错误日志位于功能控制台日志中,如下所示: 在此处输入图片说明

我有一堆云函数,但它们都失败了。我已经发布了其中一个代码量最少的实现。

exports.isUserRunningMinimumVersion = functions.database
  .ref('/tasks/isUserRunningMinimumVersion/{taskId}')
  .onCreate((taskSnapshot, context) => {
    if (!taskSnapshot.exists()) {
      return
    }
    const task = taskSnapshot.val()

    invariant(
      task.hasOwnProperty('version'),
      "isUserRunningMinimumVersion task doesn't contain required fields [version]"
    )

    let promise
    if (semver.lt(task.version, GlobalConfig.minSupportedVersion)) {
      promise = ref.child('taskResults/' + context.params.taskId).set({
        status: 'success',
        result: {
          userIsRunningMinimumVersion: false,
        },
      })
    } else {
      promise = ref.child('taskResults/' + context.params.taskId).set({
        status: 'success',
        result: {
          userIsRunningMinimumVersion: true,
        },
      })
    }

    return promise.then(() => {
      return ref
        .child('/tasks/isUserRunningMinimumVersion/' + context.params.taskId)
        .remove()
    })
  })
Run Code Online (Sandbox Code Playgroud)

下面是我的 package.json 文件

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "dependencies": {
    "@sentry/node": "^5.11.1",
    "aws-sdk": "^2.620.0",
    "axios": "^0.19.0",
    "child-process-promise": "^2.2.1",
    "firebase-admin": "^8.0.0",
    "firebase-functions": "^2.3.1",
    "google-libphonenumber": "^3.2.2",
    "googleapis": "^41.0.1",
    "i18n-js": "^3.2.2",
    "install": "^0.13.0",
    "invariant": "^2.2.4",
    "lodash": "^4.17.11",
    "mkdirp-promise": "^5.0.1",
    "nexmo": "^2.4.1",
    "nodemailer": "^6.2.1",
    "npm": "^6.13.6",
    "semver": "^6.1.1",
    "useragent": "^2.3.0",
    "uuid": "^3.3.3"
  },
  "engines": {
    "node": "10"
  },
  "private": true
}
Run Code Online (Sandbox Code Playgroud)

请分享如何解决此问题。

Dou*_*son 4

您的 firebase-functions 模块非常旧。最新版本是3.8.0。升级它:

npm install firebase-functions@latest
Run Code Online (Sandbox Code Playgroud)