繁体   English   中英

在 firebase 函数中使用 got(npm) 时出现“SyntaxError: Unexpected token *”

[英]"SyntaxError: Unexpected token *" when use got(npm) in firebase functions

我正在使用“得到”作为 api 请求。

在本地运行 firebase 功能时,它运行良好。 但是,当我尝试部署时,我收到了"SyntaxError: Unexpected token *"

!  functions[app(us-central1)]: Deployment error.
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /srv/node_modules/got/dist/source/create.js:101
    got.paginate = async function* (url, options) {
                                 ^

SyntaxError: Unexpected token *
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/srv/node_modules/got/dist/source/index.js:7:18)

据我所知,生成器函数在 node.js(版本 8)中可用。 我不知道原因。

谢谢你。

已经解决了。 我自己回答。

“异步函数 *”在 node.js 版本 10 及更高版本中可用。

我的本地 node.js 版本是 12,firebase 的 node.js 版本是 8(10 是测试版)。 将 firebase 版本更改为 10 后,我就可以部署了。

但是,我放弃了在版本 10 中使用“got”并决定使用“node-fetch”。 node-fetch 适用于版本 8。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM