firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

Cannot read properties of undefined (reading 'data')

Open SK1n opened this issue 3 years ago • 1 comments

Related issues

[REQUIRED] Version info

node: v18.7.0

firebase-functions: 3.18.0

firebase-tools: 11.4.0

firebase-admin: 11.4.0

[REQUIRED] Test case

Run a simple function using the emulator suite.

[REQUIRED] Steps to reproduce

Run the function by accessing the following link: http://localhost:$port/$project/us-central1/MoveOldEvents-0

[REQUIRED] Expected behavior

The data inside the document "test" should be printed

[REQUIRED] Actual behavior

The data inside the emulator isn't printed and an error is thrown This is the function that I try to run:

exports.MoveOldEvents = functions.pubsub.schedule("every 1 minutes").timeZone("Europe/Bucharest").onRun(async (context) => {
  const eventsRef = admin.firestore().collection("collection").doc("test");
  console.log(eventsRef);
  const doc = await eventsRef.get();

  if (!doc.exists) {
    console.log('No such document!');
  } else {
    console.log('Data: ', doc.data());
  }
});

And this is the error that I get:

TypeError: Cannot read properties of undefined (reading 'data') at processBackground (/home/$user/.nvm/versions/node/v18.7.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:551:24) at invokeTrigger (/home/$user/.nvm/versions/node/v18.7.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:641:19) at handleMessage (/home/$user/.nvm/versions/node/v18.7.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:741:15) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Were you able to successfully deploy your functions?

SK1n avatar Jul 28 '22 18:07 SK1n

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Jul 28 '22 18:07 google-oss-bot