2

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

nilesh93
  • 419
  • 3
  • 17

4 Answers4

2

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)
Nobuhito Kurose
  • 538
  • 5
  • 12
  • For the sake of time, According to the documentation, to use a Node 6 runtime you need to use a firebase-admin version lower than 8.0.0 and a firebase-functions version lower than 3.0.0. But just change to Node 8, since Node 6 will soon not be supported, and Node 10 is atill in beta on GCP. Link: https://firebase.google.com/docs/functions/manage-functions#set_runtime_options – KayO Apr 15 '20 at 18:59
0

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

sashok_bg
  • 2,436
  • 1
  • 22
  • 33
0

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.

Faruk
  • 5,438
  • 3
  • 30
  • 46
-1

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

nilesh93
  • 419
  • 3
  • 17