Reputation: 419
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
Upvotes: 2
Views: 1427
Reputation: 558
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)
Upvotes: 2
Reputation: 5841
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.
Upvotes: 0
Reputation: 419
I manually went to GCP and deleted the cloud functions and deployed again and it worked.
Upvotes: -1
Reputation: 3029
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
Upvotes: 0