[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

TypeError: admin.firestore.FieldPath is not a constructor in v11+ in Emulator mode only #1979

Closed
nerdlibfront opened this issue Nov 15, 2022 · 2 comments

Comments

@nerdlibfront
Copy link

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

I hope so. This might be a problem with the Emulator, not sure...

[REQUIRED] Step 2: Describe your environment

  • Operating System version: macOS Monterey 12.6 (also happened on Ubuntu machines)
  • Firebase SDK version: 11.12.1
  • Firebase Product: functions
  • Node.js version: 16.18.1
  • NPM version: 8.19.2

[REQUIRED] Step 3: Describe the problem

Starting with version 11 of the admin SDK creation of an admin.firestore.FieldPath object does throw an error (in Emulator only).
The call still works when deployed to Firebase.

Error happening:

⚠  functions: TypeError: admin.firestore.FieldPath is not a constructor

Steps to reproduce:

Just call new admin.firestore.FieldPath("test") in a firebase function in emulator environment.

A detailed reproduction with a minimal example is displayed here:
https://github.com/nerdlibfront/firebase-admin-fieldpath-problem

This leads to:

⚠  functions: TypeError: admin.firestore.FieldPath is not a constructor
    at /###/functions/lib/index.js:11:18
    at cloudFunction (/###/functions/node_modules/firebase-functions/lib/cloud-functions.js:78: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)

Relevant Code:

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

admin.initializeApp();

export const 
    .firestore
    .document("/test/{testId}")
    .onWrite(async (change) => {
      const path = new admin.firestore.FieldPath("test");
      const item = await admin.firestore().collection("test")
          .where(path, "==", "test")
          .get();
      console.log(item.docs.length);
    });

Error only happens in emulator, not on deployed functions.

Downgrading to firebase-admin 10 solves the problem.

@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

Please see my comment on #1973 (comment)

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 try the modular entry points instead of using the global admin namespace.

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

3 participants