Cloud Functions 部署失败:"Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded."
Cloud Functions deployment fails: "Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded."
我将我的 firebase-functions 模块升级到了 3.0.1。现在,当我部署 Cloud Functions 时,我收到警告消息:
⚠ functions: Deploying functions to Node 6 runtime, which is deprecated. Node 8 is available and is the recommended runtime.
然后,部署失败:
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 不支持该关键字。
我将我的 firebase-functions 模块升级到了 3.0.1。现在,当我部署 Cloud Functions 时,我收到警告消息:
⚠ functions: Deploying functions to Node 6 runtime, which is deprecated. Node 8 is available and is the recommended runtime.
然后,部署失败:
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 不支持该关键字。