You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Firestore] admin.firestore.Timestamp.now() fails with firebase-admin 11, works in 10.3 (emulator) #1827
Thank you for reporting this issue. This might have been caused by the Firestore version bump in Admin SDK v11.
In the meantime could try adding import { Timestamp } from 'firebase-admin/firestore' as a workaround? It seemed to have worked in #1793
Thank you for reporting this issue. This might have been caused by the Firestore version bump in Admin SDK v11.
In the meantime could try adding import { Timestamp } from 'firebase-admin/firestore' as a workaround? It seemed to have worked in #1793
import * as admin from 'firebase-admin';
admin.initializeApp();
const f = admin.firestore();
const t = admin.firestore.Timestamp.now();
const fv = admin.firestore.FieldValue.delete();
It seems like as we move on to the modular SDK we should import the types as needed. The following seems to work for me:
So is this the way of using the new version of the library with typescript? I can update my code accordingly, just want to make sure this is the correct solution or just a temporary fix.
Also, can the library be fixed so the old way isn't an option in typescript anymore? Right now the error is thrown only at runtime but the types think it's okay as is (which it obviously isn't).
@Joebayld yes, if you are using the modular SDK then this is the correct way to import the types. For the issue you are facing with the previous syntax, could you provide us with a minimal repro by any chance? Thank you!
@Joebayld yes, if you are using the modular SDK then this is the correct way to import the types. For the issue you are facing with the previous syntax, could you provide us with a minimal repro by any chance? Thank you!
I think I see the issue then. I was using the older style imports (which worked in v10 and v11, but had the runtime issue).
With the above code on the latest version, this appears to be fine in typescript but doesn't work. I switched everything to the new modular imports and it seems to be okay.
Running my jest tests for code, which imports getFirestore the modular way now fails.
It is unhappy with the following statement in the /node_modules/firebase-admin/lib/esm/firestore/index.js file.
import mod from "../../firestore/index.js";
It says: SyntaxError: Cannot use import statement outside a module
Has anyone experienced this issue as well or knows how to fix it?
Since it seems like switching to the modular SDK is the proper fix here I will convert this issue to a discussion. That will hopefully help with future issues like #1954
Activity
google-oss-bot commentedon Jul 21, 2022
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Joebayld commentedon Jul 23, 2022
It appears I'm having the same issue with the
deleteFieldValue. I get this errorTypeError: Cannot read properties of undefined (reading 'delete').This looks to be yet another bug that has happened with firebase code releases. It seems like something always breaks on major releases these days.
AkshayChhajed1998 commentedon Aug 1, 2022
I am having same issues on emulator with
new admin.firestore.Timestamp(s,ns)says Timestamp() is not the constructor , but works good livemilo- commentedon Aug 2, 2022
Also experiencing the same issue, and
firestore.v1.FirestoreAdminClientis also undefinedmagician11 commentedon Aug 2, 2022
I rolled back to
v10.3.0andadmin.firestore.Timestamp.now()works again.lahirumaramba commentedon Aug 2, 2022
Thank you for reporting this issue. This might have been caused by the Firestore version bump in Admin SDK
v11.In the meantime could try adding
import { Timestamp } from 'firebase-admin/firestore'as a workaround? It seemed to have worked in #1793tofsjonas commentedon Aug 3, 2022
When I do
import { Timestamp } from 'firebase-admin/firestore'I get this:😢
This seems to work:
import type { DocumentReference, DocumentData, Timestamp } from 'firebase-admin/firestore'🤔🤯Joebayld commentedon Aug 4, 2022
What about for the delete field value?
Any idea when this can be patched?
lahirumaramba commentedon Aug 8, 2022
It seems like as we move on to the modular SDK we should import the types as needed.
The following seems to work for me:
Node.js
TypeScript
TypeScript
tsconfig.json
package.json
tofsjonas commentedon Aug 9, 2022
Ah.
The problem was (is)
eslint-plugin-import😢This will throw lint errors:
whereas this will not (which I only tried because I copy/pasted your code):
The "solution" is to not use the plugin anymore. But I would like to..
Do you have any idea what that's about?
Failing eslintrc.js:
Passing eslintrc.js:
Joebayld commentedon Aug 11, 2022
So is this the way of using the new version of the library with typescript? I can update my code accordingly, just want to make sure this is the correct solution or just a temporary fix.
Also, can the library be fixed so the old way isn't an option in typescript anymore? Right now the error is thrown only at runtime but the types think it's okay as is (which it obviously isn't).
lahirumaramba commentedon Aug 11, 2022
@Joebayld yes, if you are using the modular SDK then this is the correct way to import the types. For the issue you are facing with the previous syntax, could you provide us with a minimal repro by any chance? Thank you!
Joebayld commentedon Aug 11, 2022
I think I see the issue then. I was using the older style imports (which worked in v10 and v11, but had the runtime issue).
With the above code on the latest version, this appears to be fine in typescript but doesn't work. I switched everything to the new modular imports and it seems to be okay.
JFGHT commentedon Aug 24, 2022
With the non-modular approach, we are having the same problem.
ansells commentedon Aug 24, 2022
I'm having this same issue and had to explicitly ignore the rule for this import:
pascalbe-dev commentedon Aug 26, 2022
I also stumbled across that issue. Using the modular imports fixed the issue. Thanks for the hint :)
I think - since this is a breaking change in usage with the emulator - this should be noted in the release notes.
pascalbe-dev commentedon Aug 26, 2022
Running my jest tests for code, which imports
getFirestorethe modular way now fails.It is unhappy with the following statement in the
/node_modules/firebase-admin/lib/esm/firestore/index.jsfile.It says:
SyntaxError: Cannot use import statement outside a moduleHas anyone experienced this issue as well or knows how to fix it?
Roll back firebase-admin to 10.3.0 due to firebase/firebase-admin-nod…
mariamghalleb commentedon Oct 25, 2022
import * as firestore from 'firebase-admin/firestore'fixed it for me
abMarlim commentedon Oct 27, 2022
@ lahirumaramba you are a lifesave, thanks <3
lahirumaramba commentedon Oct 27, 2022
Since it seems like switching to the modular SDK is the proper fix here I will convert this issue to a discussion. That will hopefully help with future issues like #1954