Repository navigation
Closed
Labels
Description
Environment info
my directory structure is as so:
project
- app (react typescript)
- functions (vanilla js)
- index.js
- package.json
- src
- package.json
- functions (vanilla js)
package for my host app (react / typescript):
"firebase": "^9.17.0",
package for functions
"firebase-admin": "^11.2.0",
"firebase-functions": "^4.4.0",
firebase-tools: 12.3.1
Platform:: m1 Mac
Test case
Accessing anything from FieldValue creates error as FieldValue is undefined.
[REQUIRED] Steps to reproduce
In production, the problem is not present. When using the emulator, FieldValue is undefined.
Examples where issues persist:
time: admin.firestore.FieldValue.serverTimestamp()
Error:
Cannot read properties of undefined (reading 'serverTimestamp')
admins: admin.firestore.FieldValue.arrayUnion(uid)
Error:
Cannot read properties of undefined (reading 'arrayUnion')
console.log(admin.firestore.FieldValue)
undefined
[REQUIRED] Expected behavior
The timestamp should be saved to the object as it does when I deploy.
[REQUIRED] Actual behavior
error:
13:36:20
I
function[us-central1-onCreateLabel]
Beginning execution of "us-central1-onCreateLabel"
13:36:20
I
function[us-central1-onCreateLabel]
{
"severity": "INFO",
"message": "error TypeError: Cannot read properties of undefined (reading 'serverTimestamp')\n at /Users/thomasw.smith/Documents/Bitrip/GitLab/bitrip-webv2/functions/hooks/onCreateLabel.js:68:26\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async runFunction (/Users/thomasw.smith/.nvm/versions/node/v16.14.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:506:9)\n at async runBackground (/Users/thomasw.smith/.nvm/versions/node/v16.14.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:517:5)\n at async processBackground (/Users/thomasw.smith/.nvm/versions/node/v16.14.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:501:5)\n at async /Users/thomasw.smith/.nvm/versions/node/v16.14.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:689:21"
}
13:36:20
W
function[us-central1-onCreateLabel]
Error: Error at onCreateLabel hook
at /Users/thomasw.smith/Documents/Bitrip/GitLab/bitrip-webv2/functions/hooks/onCreateLabel.js:82:13
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runFunction (/Users/thomasw.smith/.nvm/versions/node/v16.14.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:506:9)
at async runBackground (/Users/thomasw.smith/.nvm/versions/node/v16.14.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:517:5)
at async processBackground (/Users/thomasw.smith/.nvm/versions/node/v16.14.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:501:5)
at async /Users/thomasw.smith/.nvm/versions/node/v16.14.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:689:21
13:36:20
W
function[us-central1-onCreateLabel]
Your function was killed because it raised an unhandled error.
Activity
aalej commentedon Jun 12, 2023
Hi @TS22082, thanks for reaching out to us. I would like to reproduce this behavior you’re encountering. Would it be okay if you could provide me with an MCVE I can run locally, or sample code snippets from your
functions/index.jsfile showing how you’re importing the firebase-admin sdk?TS22082 commentedon Jun 14, 2023
The issue was caused by the way I was importing.
This worked:
This did not: