Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to complete this codelab: Please update the source code to support latest versions #831

Open
lisamariet opened this issue Dec 20, 2024 · 0 comments
Labels

Comments

@lisamariet
Copy link

lisamariet commented Dec 20, 2024

Main problem: The code is outdated.

NOTE: urls have been sensured with 'xxxx'

SUMMARY

  • It is based on node v12 and old modules that is now deprecated or not supported anymore. Please update the code to the latest node version and latest firebase-tools, firebase-functions and firebase-admin.
  • Missing instructions steps for Firebase Console setup
  • using 1st gen Functions code, and when searching for help find 2nd gen code. Please update the code to use 2nd gen functions coding.

DETAILS

I tried to follow this codelab but there are several problems:

1. Outdated node v12 and dependency modules

It is Based on outdated node v12 and old firebase-tools that is not working. I tried getting everything onto node v12 and dependencies supporting that, but that would not run the command firebase deploy --except functions results in:

There was an issue deploying your functions. Verify that your project has a Google App Engine instance setup at https://console.cloud.google.com/appengine and try again. If this issue persists, please contact support.
Error: HTTP Error: 404, Resource 'projects/friendlychat-xxxx/locations/global/applications/friendlychat-xxxx' was not found

I can only get this command to run when upgrading to at least node v18. Then the command run and deployed (after I created Firebase Database - ref issue 2 below).

2. Missing instructions about setting up Firestore

Instructions are missing the step of setting up the Firestore Database

3. issue deploying on step 8: Deploy Cloud Functions

I have written the code in the step but running the command:
firebase deploy --only functions

Failes with error:
Error: Cannot understand what targets to deploy/serve. No targets in firebase.json match '--only functions'.
And true enough there is no such thing in firebase.json

I am guessing this might be related to newer version of firebase-tools? Not sure.
It did say that cloud-functions has the complete solution but the command does not work in that folder either.

my solution

I added these lines in firebase.json, not totally sure it is correct

  "functions": {
    "source": "functions"
  }

This did get the deploy --only functions to get a little further:

=== Deploying to 'friendlychat-xxxx'...

i  deploying functions
i  functions: preparing codebase default for deployment
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
⚠  functions: missing required API cloudfunctions.googleapis.com. Enabling now...
⚠  artifactregistry: missing required API artifactregistry.googleapis.com. Enabling now...
⚠  functions: missing required API cloudbuild.googleapis.com. Enabling now...
✔  functions: required API cloudfunctions.googleapis.com is enabled
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
⚠  functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory.
⚠  functions: Please note that there will be breaking changes when you upgrade.
i  functions: Loading and analyzing source code for codebase default to determine what to deploy
i  functions: You are using a version of firebase-functions SDK (4.9.0) that does not have support for the newest Firebase Extensions features. Please update firebase-functions SDK to >=5.1.0 to use them correctly
Serving at port 8347

i  functions: preparing functions directory for uploading...
i  functions: packaged /Users/lisamariet/Git/vivende/friendlychat/cloud-functions-start/functions (123.53 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: creating Node.js 18 (1st Gen) function addWelcomeMessage(us-central1)...
⚠  functions: failed to create function projects/friendlychat-xxxx/locations/us-central1/functions/addWelcomeMessage
Failed to create function projects/friendlychat-xxxx/locations/us-central1/functions/addWelcomeMessage

Functions deploy had errors with the following functions:
	addWelcomeMessage(us-central1)
i  functions: cleaning up build files...
⚠  functions: Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. You can attempt to delete these images by redeploying or you can delete them manually at https://console.cloud.google.com/gcr/images/friendlychat-xxxx/us/gcf

Error: There was an error deploying functions

So I upgrade to firebase-functions@5 + firebase-admin@11.
This still gives me an error that firebase-functions are outdated, but at least the deploy worked and the function addWelcomeMessage actually worked as well.
However again it would be nice if the code was updated to non-outdated versions.

4. Issue getting the blured function to work on step 9.

I have added the code and successfully deployed the function. Enabled the Cloud Vision API. But when uploading the zoombie image from the instructions, it is not blurred.

Error in function logs:

{
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "status": {
      "code": 13,
      "message": "Failed to configure trigger providers/cloud.storage/eventTypes/object.change"
    },
    "authenticationInfo": {},
    "serviceName": "cloudfunctions.googleapis.com",
    "methodName": "google.cloud.functions.v1.CloudFunctionsService.CreateFunction",
    "resourceName": "projects/friendlychat-xxxx/locations/us-central1/functions/blurOffensiveImages"
  },
  "insertId": "2096eud251o",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "region": "us-central1",
      "function_name": "blurOffensiveImages",
      "project_id": "friendlychat-xxxx"
    }
  },
  "timestamp": "2024-12-20T12:58:33.198365Z",
  "severity": "ERROR",
  "logName": "projects/friendlychat-xxxx/logs/cloudaudit.googleapis.com%2Factivity",
  "operation": {
    "id": "operations/ZnJpZW5kbHljaGF0LTc3ZjFhL3VzLWNlbnRyYWwxL2JsdXJPZmZlbnNpdmVJbWFnZXMvRTYwQzNkamhBZnM",
    "producer": "cloudfunctions.googleapis.com",
    "last": true
  },
  "receiveTimestamp": "2024-12-20T12:58:34.125677473Z"
}

I am not sure what the actual issue here is. But after running eslint on the code it says there is a missing return statement on that blurOffensiveImages function so I add return null; at the end and that made the trick. But I spent a good time trying to figure out what was from from the log messages.

5. Bad instructions on Step 10 send notifications, code fails

  • the code to get the tokens are not getting the uid.

Error in function logs:

{
  "textPayload": "Error: Registration token provided to sendToDevice() at index 0 must be a non-empty string.\n    at /workspace/node_modules/firebase-admin/lib/messaging/messaging.js:881:27\n    at Array.forEach (<anonymous>)\n    at Messaging.validateRegistrationTokens (/workspace/node_modules/firebase-admin/lib/messaging/messaging.js:879:39)\n    at /workspace/node_modules/firebase-admin/lib/messaging/messaging.js:436:18\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async /workspace/index.js:139:30",
  "insertId": "676579f400077c2804f5a7df",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "region": "us-central1",
      "project_id": "friendlychat-xxxx",
      "function_name": "sendNotifications"
    }
  },
  "timestamp": "2024-12-20T14:06:44.490536Z",
  "severity": "ERROR",
  "labels": {
    "execution_id": "hgsisu4z1rgx",
    "runtime_version": "nodejs18_20241208_18_20_5_RC00",
    "instance_id": "0066d92480f532a7d026b4a383cfb4c19adf27311bd9a1491aa5deaa08909f4eee1f1cf97d5b38839569b521f0cce87f01ab9f8fca60a28e7e3958296825ab1cc76e71c018f64e089bbed4d89a64a8"
  },
  "logName": "projects/friendlychat-xxxx/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
  "trace": "projects/friendlychat-xxxx/traces/0fbae1d7507e76e33d65a8bce27aec2d",
  "receiveTimestamp": "2024-12-20T14:06:44.609975243Z",
  "errorGroups": [
    {
      "id": "CIjowNu18Nv16gE"
    }
  ]
}
  • it is using a deprecated .sendToDevice function.

Error in function logs:

{
  "textPayload": "Failure sending notification to fhVLCI1cFjULfHj6PSvReux5uO63 FirebaseMessagingError: An unknown server error was returned. Raw server response: \"\"DeprecatedApi\"\"\n    at FirebaseMessagingError.fromServerError (/workspace/node_modules/firebase-admin/lib/utils/error.js:254:16)\n    at /workspace/node_modules/firebase-admin/lib/messaging/messaging.js:93:65\n    at Array.forEach (<anonymous>)\n    at mapRawResponseToDevicesResponse (/workspace/node_modules/firebase-admin/lib/messaging/messaging.js:89:26)\n    at /workspace/node_modules/firebase-admin/lib/messaging/messaging.js:456:24\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async /workspace/index.js:143:30 {\n  errorInfo: {\n    code: 'messaging/unknown-error',\n    message: 'An unknown server error was returned. Raw server response: \"\"DeprecatedApi\"\"'\n  },\n  codePrefix: 'messaging'\n}",
  "insertId": "6765817300018868fda9c080",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "project_id": "friendlychat-xxxx",
      "region": "us-central1",
      "function_name": "sendNotifications"
    }
  },
  "timestamp": "2024-12-20T14:38:43.100456Z",
  "severity": "ERROR",
  "labels": {
    "instance_id": "0066d924804269945e1b8a5d76bce582091d0174dd43f6d590f9163bc6ed3a60d3eb3cf2c2cb782c989fadec9ddc24026898342439243f341cefc434914ab72797f545b37d7fc0ed28f6b2d758cb83",
    "runtime_version": "nodejs18_20241215_18_20_5_RC00",
    "execution_id": "qroybcccwzop"
  },
  "logName": "projects/friendlychat-xxxx/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
  "trace": "projects/friendlychat-xxxx/traces/9e9679b832bcd55d81792e82ff2b39a1",
  "receiveTimestamp": "2024-12-20T14:38:43.224122362Z",
  "errorGroups": [
    {
      "id": "CJX1oYP35t3sdQ"
    }
  ]
}
  • I changed to use fetch token uid property and changed to use the .sendEachForMulticast(MulticastMessage) method. But it seems that the Fcm token is not valid.

Error log showing:

{
  "textPayload": "Failure sending notification to fhVLCI1cFjULfHj6PSvReux5uO63 FirebaseMessagingError: The registration token is not a valid FCM registration token\n    at FirebaseMessagingError.fromServerError (/workspace/node_modules/firebase-admin/lib/utils/error.js:254:16)\n    at createFirebaseError (/workspace/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.js:35:47)\n    at FirebaseMessagingRequestHandler.buildSendResponseFromError (/workspace/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.js:155:72)\n    at /workspace/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.js:106:29\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async Promise.allSettled (index 1)\n    at async /workspace/index.js:146:30 {\n  errorInfo: {\n    code: 'messaging/invalid-argument',\n    message: 'The registration token is not a valid FCM registration token'\n  },\n  codePrefix: 'messaging'\n}",
  "insertId": "67659338000ddbe5b2411dc2",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "function_name": "sendNotifications",
      "region": "us-central1",
      "project_id": "friendlychat-xxxx"
    }
  },
  "timestamp": "2024-12-20T15:54:32.908261Z",
  "severity": "ERROR",
  "labels": {
    "runtime_version": "nodejs18_20241215_18_20_5_RC00",
    "instance_id": "0066d924806b193d8b2cdc393c76f5ed91772594865a59370e45b937afc1e18c815e340bc792ae3fe17e14d519c7c99a52aea11e3bd8cab3c7fe0ca2175077978278d0d2507ef3f8e6cc8d3d793113",
    "execution_id": "ohsvjzfk3bzz"
  },
  "logName": "projects/friendlychat-xxxx/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
  "trace": "projects/friendlychat-xxxx/traces/fb7eea62010deaf0463b001098bc5dd9",
  "receiveTimestamp": "2024-12-20T15:54:33.025414194Z",
  "errorGroups": [
    {
      "id": "CMH40Jap0rrBDQ"
    }
  ]
}
@lisamariet lisamariet added the bug label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant