云函数部署失败:"Function failed on loading user code. Error message: Code in file lib/index.js can't be lo



我将Firebase函数模块升级到3.0.1。 现在,当我部署云函数时,我收到警告消息:

⚠ 函数:将函数部署到节点 6 运行时,已弃用。节点 8 可用,是推荐的运行时。

然后,部署失败,如下所示:

Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/node_modules/firebase-functions/lib/providers/https.js:282
    const func = async (req, res) => {
                       ^
SyntaxError: Unexpected token (
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/index.js:39:15)

我该如何解决这个问题?

过去,节点 6 是默认的目标运行时。 现在,节点 6 的 LTS(长期支持(已过期。 在 CLI 版本 6.8.0 中,已弃用节点 6,建议您改为以节点 8 为目标进行部署。 现在,从 firebase-functions@3.0.0 开始,节点 6 支持已完全删除,您必须在 package.json 中明确定位节点 8:

{
  // other configurations here…
  "dependencies": {
  },
  // Add an “engines” child to choose a node version, here it’s node 8.
  "engines": {
    "node": "8"
  }
}

此版本中的另一个相关更改是对 firebase-admin 8.x 的依赖,它也放弃了对节点 6 的支持。

错误消息本身指示无法识别关键字 async,节点 6 不支持该关键字。

相关内容

最新更新