https://github.com/ThomasKientz/nuxt-firestore-repro
npm install
npm run dev
navigate to website.
check the console.
The firebase query to execute without any errors.
On server side (from a page reload), the firebase library produces an error. It looks like the firestore js library doesn't recognize objects from the async hook. Maybe nuxt is modifying prototypes or is messing with objects.
I am trying to query data by date from Firestore with Nuxt in an Universal App :
asyncData() {
citiesRef
.where("date", ">", new Date())
.get()
.then(() => {
console.log("ok");
})
return {};
}
But I get the error when loading from the server side (not happening in client side) :
Function Query.where() called with invalid data. Unsupported field value: a custom Date object
Similar error with :
asyncData() {
citiesRef
.add({
name: "Tokyo"
})
.then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
});
return {};
}
Function CollectionReference.add() requires its first argument to be of type object, but it was: a custom Object object
It doesn't happen with the client side context.
It's doesn't appear to be a firebase error as I can not reproduce this on a simple node env with the same lib : https://github.com/ThomasKientz/firestore-node-repro
Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:
Issues that are labeled as pending will not be automatically marked as stale.
const firebase = require("firebase/app");
citiesRef
.where("date", ">", firebase.firestore.Timestamp.fromDate(new Date()))
.get()
.then(() => {
console.log("ok");
})
return {};
@1919yuan this solution worked for me. Thanks!