LABR
LABR

Reputation: 23

parameter in cloud functions is undefined

I have an old code for Google Cloud Functions, it resized an image to create a thumbnail, I wrote it three years ago and was in NodeJS 6, it was working fine but i had to update to NodeJS 10, i added

"engines": {
    "node": "10"
  }

other functions continued working but this not

exports.generateThumbnail = functions.storage.object().onFinalize(async (object) => {
    const contentType = object.contentType;

it throws an error when i try to access "object" apparently is undefined, the log error is

TypeError: Cannot read property 'contentType' of undefined
    at exports.generateThumbnail.functions.storage.object.onFinalize (/workspace/index.js:30:32)
    at cloudFunctionNewSignature (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:120:23)
    at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:151:20)
    at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:199:28)
    at process._tickCallback (internal/process/next_tick.js:68:7) 

I updated firebase-admin, firebase-functions, google-cloud-storage, but it did not solve my problem What could have happened and how do I solve it?

Upvotes: 2

Views: 858

Answers (1)

Rafael Lemos
Rafael Lemos

Reputation: 5829

In this Github issue other users were facing the same issue you are, the propose solution had to do with the need to set a new variable in order to refresh the objects in your function and redeploying it.

So, if you were to add a new variable to your to your index.js like this:

process.env.X_GOOGLE_NEW_FUNCTION_SIGNATURE = true;

And redeploy the function, the issue is suppose to be fixed.

Upvotes: 1

Related Questions