[go: nahoru, domu]

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

[Firestore] firebase-admin sdk "FieldValue.serverTimestamp" fails from v11.0.0 #1973

Closed
OutdatedGuy opened this issue Nov 14, 2022 · 3 comments

Comments

@OutdatedGuy
Copy link

[READ] Step 1: Are you in the right place?

Cloud Firestore support is provided by the @google-cloud/firestore library. Therefore the easiest and most efficient way to get Firestore issues resolved is by directly reporting them at the nodejs-firestore GitHub repo.

If you still think the problem is related to the code in this repository, then read on.

  • For issues or feature requests related to the code in this repository
    file a Github issue.
  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the firebase-talk
    google group.
  • For help troubleshooting your application that does not fall under one
    of the above categories, reach out to the personalized
    Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Operating System version: macOS Ventura 13.0.1
  • Firebase SDK version: "firebase-admin": "^11.0.0"
  • Firebase Product: Firestore
  • Node.js version: v16.17.1
  • NPM version: 8.15.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

The firestore FieldValue.serverTimestamp() fails starting from v11.0.0 of firebase-admin sdk. It was working fine till v10.3.0.

  1. Export the code sample from index.ts file
  2. Start firebase auth, firestore and functions emulator with cmd npm run build && firebase emulators:start
  3. From the emulator UI of auth create a new user
  4. See crash in terminal
i  functions: Beginning execution of "newUser"
⚠  functions: TypeError: Cannot read properties of undefined (reading 'serverTimestamp')
    at /Users/omphatak/Work/5amClub/5amClub-Cloud-Functions/functions/lib/auto/newUser.js:8:47
    at cloudFunction (/Users/omphatak/Work/5amClub/5amClub-Cloud-Functions/functions/node_modules/firebase-functions/lib/v1/cloud-functions.js:79:23)
    at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:516:16
    at runFunction (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:504:15)
    at runBackground (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:515:11)
    at processBackground (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:499:11)
    at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:690:27
    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/layer.js:95:5)
    at next (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/route.js:137:13)
    at next (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/route.js:131:14)
⚠  Your function was killed because it raised an unhandled error.

Relevant Code:

import * as admin from "firebase-admin";
import * as functions from "firebase-functions";

export const newUser = functions.auth.user().onCreate(async (user) => {
  await admin.firestore().collection("users").doc(user.uid).set({
    createdAt: admin.firestore.FieldValue.serverTimestamp(),
  });
});
@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@lahirumaramba
Copy link
Member

Hi @OutdatedGuy , we have seeing reports of this issue occuring sometimes when using the global admin namespace. Importing the global admin namespace is deprecated and namespaces will be removed in the future. We recommend developers to use the new modular entry points to access the various APIs of the SDK, as opposed to using the global admin namespace.

Please see the discussion for more info: #1959 (comment)

@jorroll
Copy link
jorroll commented Dec 5, 2022

@lahirumaramba I just ran into this issue as well after upgrading to version 11.x. I'm also using the global admin namespace.

Importing the global admin namespace is deprecated and namespaces will be removed in the future

Deprecated does not mean removed. Based on your comment, it sounds like importing from the admin namespace is broken with no plans on a fix. Is there any reason why dropping support for the admin namespace isn't included in the release notes as a breaking change? Otherwise, this issue should be reopened.

Looking at #1959, it seems like the v11 release notes should be updated to note that importing from the global admin namespace is now broken in subtle ways and affected users should read #1959 for more information.

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

No branches or pull requests

4 participants