首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >云函数部署失败:加载用户代码失败,错误信息:无法加载lib/index.js文件中的代码。

云函数部署失败:加载用户代码失败,错误信息:无法加载lib/index.js文件中的代码。
EN

Stack Overflow用户
提问于 2019-06-13 07:13:39
回答 1查看 10.4K关注 0票数 15

我将firebase-functions模块升级到了3.0.1。现在,当我部署Cloud Functions时,我收到警告消息:

⚠functions:将函数部署到Node6运行时,已弃用。Node 8是可用的,并且是推荐的运行时。

然后,部署失败,并显示以下内容:

代码语言:javascript
复制
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)

我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-13 07:13:39

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

代码语言:javascript
复制
{
  // 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不支持的。

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56571460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档