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

Oza*_*Oza 5 javascript node.js firebase google-cloud-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)
Run Code Online (Sandbox Code Playgroud)

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

谢谢你。

Oza*_*Oza 11

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

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

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

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