Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using "got" for api request.

It worked fine when running firebase functions locally. However, when I tried to deploy, I got "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)

As far as i know, the generator function be available in node.js (version 8). I don't know the cause.

Thank you.

like image 304
Oza Oza Avatar asked Mar 12 '20 01:03

Oza Oza


1 Answers

It has been resolved. I answer myself.

"async function * " is available in node.js version 10 and later.

My local node.js version was 12, and firebase's node.js version is 8 (10 is beta). After change firebase version to 10, I was able to deploy.

But, I gave up using "got" with version 10 and decided to use "node-fetch". node-fetch works with version 8.

like image 192
Oza Oza Avatar answered Sep 28 '22 18:09

Oza Oza