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

Firebase cloud functions "error": "\"length\" is outside of buffer bounds" #519

Open
Mapenergo opened this issue Aug 26, 2024 · 2 comments

Comments

@Mapenergo
Copy link

Mapenergo commented Aug 26, 2024

Working on MacOS v 14.6.1 Apple M2 node 22.7.0 npm 10.8.2

I passed through the lesson https://firebase.google.com/docs/functions/get-started?hl=en&gen=2nd

And encountered an error ""length" is outside of buffer bounds" after running the function: http://127.0.0.1:5001/povarcloud/us-central1/addmessage

How can I fix it?

Here is the code:

const {logger} = require("firebase-functions");
const {onRequest} = require("firebase-functions/v2/https");
const {onDocumentCreated} = require("firebase-functions/v2/firestore");

// The Firebase Admin SDK to access Firestore.
const {initializeApp} = require("firebase-admin/app");
const {getFirestore} = require("firebase-admin/firestore");

initializeApp();

// Take the text parameter passed to this HTTP endpoint and insert it into
// Firestore under the path /messages/:documentId/original
exports.addmessage = onRequest(async (req, res) => {
    const original = req.query.text;
  
    if (!original) {
      res.status(400).json({error: "Text parameter is required"});
      return;
    }
  
    try {
      const writeResult = await getFirestore()
          .collection("messages")
          .add({original: original});
      res.json({result: `Message with ID: ${writeResult.id} added.`});
    } catch (error) {
      res.status(500).json({error: error.message});
    }
  });

UPD: I've fixed it by installing Node 20 instead of Node 22.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@Mapenergo and others