javascriptfirebasegoogle-cloud-firestore

How to fix "Uncaught TypeError: Cannot read property 'Timestamp' of undefined"?


Hi I'm new in web development and I'm trying to make a firebase app with the firestore database. I have a user registration form and in this form I need to get the date. For the date I used datepicker but I can't get the selected date and after transform it into firestore Timestamp. I tried this but I don't know if something is correct:
Html form:

<input class="datepicker" type="text" id="subscriptionDeadline" placeholder="Subscription Deadline">

Javascript code:

  var currentDate = $(".subscriptionDeadline").datepicker("getDate");
  var timeStamp = new firebase.firestore.Timestamp.fromDate(currentDate);

I get this error :

Uncaught TypeError: Cannot read property 'Timestamp' of undefined


Solution

  • Your error is Cannot read property 'Timestamp' of undefined. In the code, it is trying to access firebase.firestore.Timestamp.

    The error is saying that whatever you are trying to read the property Timestamp from, is undefined. In your case it is firebase.firestore. If you do a console.log(firebase.firestore) it will show undefined, which means you won't be able to access the Timestamp property or anything else.

    It sounds like the problem is you haven't initialized firestore properly on your page. Make sure you have followed these steps: https://cloud.google.com/firestore/docs/quickstart-mobile-web#set_up_your_development_environment