2
votes

I have been using firebase cloud functions for some time now and did a minor bug fix today in my code and got the following error when tried to deploy. I undid that change and tried to deploy again with the last committed stable change, but still the same error. Any solutions? PS: This is a typescript project and I compile it with tsc.

Deployment error. Function load error: 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/request/node_modules/sntp/lib/index.js:19 exports.time = async function (options = {}) { ^^^^^^^^ SyntaxError: Unexpected token function

4
what node version are you using?Peter Haddad
I just started having the same issue as of today. Friday everything worked fine. My node version is v6.11.5 and npm 3.10.10sashok_bg
the same error as above @sashok_bg?Peter Haddad
does it matter? as in it gets deployed in firebase which runs in node 6+ something I guess. Typescript compilation works. My node version however is 8.5.0nilesh93
Exactly the same but using gcloud instead of firebasesashok_bg

4 Answers

2
votes

I got the same kind of error.
In my case, changing Node version to 8 fixed this error.

https://medium.com/google-cloud/migrating-firebase-cloud-functions-to-node-8-aebdb0d3d9a9

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: /user_code/node_modules/@google-cloud/logging/node_modules/gaxios/build/src/index.js:28
async function request(opts) {
      ^^^^^^^^

SyntaxError: Unexpected token function
    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/@google-cloud/logging/node_modules/gtoken/build/src/index.js:18:18)
0
votes

I had the same error message using gcloud beta functions with serverless framework https://serverless.com/framework/docs/providers/google/.

I resolved my problem by deleting the local .serverless folder and updating the version of https://www.npmjs.com/package/@google-cloud/datastore to the latest and running npm install

0
votes

I've been facing the same problem but with another library called request. In your case is sntp library.

The problem is because the update of library version using async wait which is not supported.

The solution in my case is downgrade the library version in package.json (remove '^' sign) and then run npm install again in functions folder.

-1
votes

I manually went to GCP and deleted the cloud functions and deployed again and it worked.