admin管理员组

文章数量:1318564

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._pile (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.

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._pile (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.

Share Improve this question asked Mar 12, 2020 at 1:21 Oza OzaOza Oza 1711 silver badge8 bronze badges 2
  • 4 That just means the NodeJS version in the production environment is lower so it doesn't understand the generator function syntax, also I don't think Node version 8 had generator function support – Trash Can Commented Mar 12, 2020 at 1:56
  • 1 @Teedeez Thanks for your ment. I looked up more about the node.js version. generator function with async was available in node.js version 10 and later. However, Version 10 for the firebase functions is a beta version, so i will consider how to deal with it. Thank you again. – Oza Oza Commented Mar 12, 2020 at 2:35
Add a ment  | 

1 Answer 1

Reset to default 11

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.

本文标签: javascriptquotSyntaxError Unexpected token *quot when use got(npm) in firebase functionsStack Overflow