Replies: 27 comments 14 replies
-
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
Beta Was this translation helpful? Give feedback.
-
It appears I'm having the same issue with the 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. |
Beta Was this translation helpful? Give feedback.
-
I am having same issues on emulator with |
Beta Was this translation helpful? Give feedback.
-
Also experiencing the same issue, and |
Beta Was this translation helpful? Give feedback.
-
I rolled back to |
Beta Was this translation helpful? Give feedback.
-
Thank you for reporting this issue. This might have been caused by the Firestore version bump in Admin SDK |
Beta Was this translation helpful? Give feedback.
-
When I do
😢 This seems to work: |
Beta Was this translation helpful? Give feedback.
-
What about for the delete field value? Any idea when this can be patched? |
Beta Was this translation helpful? Give feedback.
-
It seems like as we move on to the modular SDK we should import the types as needed. Node.js
TypeScript
TypeScript (legacy - using the global
tsconfig.json
package.json
|
Beta Was this translation helpful? Give feedback.
-
Ah. The problem was (is) This will throw lint errors: import { getFirestore, Timestamp, FieldValue, Firestore } from 'firebase-admin/firestore';
import { initializeApp } from 'firebase-admin/app';
whereas this will not (which I only tried because I copy/pasted your code): const { initializeApp } = require('firebase-admin/app');
const { getFirestore, Timestamp, FieldValue } = require('firebase-admin/firestore'); 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: extends: [
'eslint:recommended',
'plugin:import/recommended',
'plugin:import/typescript', Passing eslintrc.js: extends: [
'eslint:recommended',
// 'plugin:import/recommended',
// 'plugin:import/typescript', |
Beta Was this translation helpful? Give feedback.
-
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). |
Beta Was this translation helpful? Give feedback.
-
@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! |
Beta Was this translation helpful? Give feedback.
-
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). import * as admin from "firebase-admin";
admin.firestore.FieldValue.delete() 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. |
Beta Was this translation helpful? Give feedback.
-
With the non-modular approach, we are having the same problem. |
Beta Was this translation helpful? Give feedback.
-
I'm having this same issue and had to explicitly ignore the rule for this import: // eslint-disable-next-line import/no-unresolved
import {Timestamp} from "firebase-admin/firestore"; |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Running my jest tests for code, which imports
It says: Has anyone experienced this issue as well or knows how to fix it? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@ lahirumaramba you are a lifesave, thanks <3 |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
@lahirumaramba did ignore eslint also the solution? because eslint user has this issue
|
Beta Was this translation helpful? Give feedback.
-
We encountered this problem when importing like this using TypeScript:
It's been a while now, but if I recall correctly, the problem didn't appear in the Emulator but it did once I deployed to the cloud. |
Beta Was this translation helpful? Give feedback.
-
Emulator vs Live deployment for firestore-admin & Timestamp imports with temporary solution. Environment:
OS: macOs Details: Using Using the following on live builds, deploys, and executes as expected: import {firestore} from "firebase-admin";
import Timestamp = firestore.Timestamp; but emulator(s) do not like it. Emulator function crashes on calling:
with stacktrace:
Using the following on emulator builds, runs, and executes as expected: import {Timestamp} from "firebase-admin/firestore"; but does not pass lint checks, see for lint bypass rule: #1359 (comment) TL;DR In module.exports = {
// ...,
rules: {
// ...
'import/no-unresolved':
[
'error',
{
ignore: ['^firebase-admin/.+'],
},
]
}
} |
Beta Was this translation helpful? Give feedback.
-
@lahirumaramba thank you for your help here, I had a question tied to this since it was a bit hard to find examples of the new modular way, especially with these timestamps and stuff. |
Beta Was this translation helpful? Give feedback.
-
This one works for me import { FieldValue } from 'firebase-admin/firestore';
..........
const data = {
createdAt: FieldValue.serverTimestamp()
} |
Beta Was this translation helpful? Give feedback.
-
This one works for me import { initializeApp } from 'firebase/app';
import { getDatabase } from 'firebase/database';
import { Timestamp } from 'firebase/firestore';
const firebaseConfig = {
....
}
const firebaseApp = initializeApp(firebaseConfig);
const database = getDatabase(firebaseApp);
const TIMESTAMP = Timestamp.now().toMillis();
function writeData(data) {
const databaseRef = ref(database, endpoint);
const newDataRef = push(databaseRef);
set(newDataRef, data);
}
const data = {
.....
createdAt: TIMESTAMP,
}
....
writeData(data); |
Beta Was this translation helpful? Give feedback.
-
This one is working for me for the CommonJS environment. const { FieldValue, Timestamp} = require("firebase-admin/firestore");
// ...
const serverTime = FieldValue.serverTimestamp();
await rateLimitRef.set({ timestamp: serverTime });
//...
const now = Timestamp.now();
const cutoff = new Date(now.toDate().getTime() - 24 * 60 * 60 * 1000); // 24 hours ago
const snapshot = await rateLimitRef.where('timestamp', '<=', cutoff).get();
|
Beta Was this translation helpful? Give feedback.
-
[REQUIRED] Step 2: Describe your environment
tsconfig.json
package.json
[REQUIRED] Step 3: Describe the problem
admin.firestore.Timestamp.now()
throws TypeError: Cannot read properties of undefined (reading 'now') (~same withadmin.firestore.increment(1)
).In emulator, I haven't dared try it "live".
Steps to reproduce / Relevant Code:
test.ts
Result:
TypeError: Cannot read properties of undefined (reading 'now')
Beta Was this translation helpful? Give feedback.
All reactions