8

Recently encountered a problem with a long standing asp.net c# program.

In my default.aspx amongst other things we have...

<script src="https://maps.googleapis.com/maps/api/js?key=...&libraries=geometry"></script>

<script src="/js/date.js" type="text/javascript"></script>

date.js is a utility library from http://www.datejs.com/

Just recently (last 6 weeks) our map is failing to draw anything, after a bit of investigation it seems that there's a toString() in one of the maps library files that tries to use the toString() from the date.js file and fails miserably.

Uncaught TypeError: format.replace is not a function
    at Date.toString (date.js:40)
    at iq (common.js:65)
    at Object._.Bq (common.js:75)
    at map.js:83

For the moment I can specify the version of google maps, 3.40 works fine, anything later doesn't.

Does anyone have a solution to this or has anyone seen this problem? Granted date.js is very old library now but I wondered if there's anything simply I can do.

Sascha
  • 4,576
  • 3
  • 13
  • 34
Richard Nixon
  • 839
  • 6
  • 9
  • 1
    related question: [format.replace is not a function - google-maps](https://stackoverflow.com/questions/63228839/format-replace-is-not-a-function-google-maps) – geocodezip Aug 04 '20 at 21:29
  • Forcing the version works for now. One solution for the future is to rename the `now()` function in date.js and change usages in the code we *do* control. The underlying problem is that date.js changes the return result type of the `now()` function. – Richard Nixon Aug 23 '20 at 18:54

3 Answers3

4

Google suggests pointing to a more recent version of date.js https://github.com/datejs/Datejs/issues/88

I haven't checked it yet but confirmed it is failing with an old date.js

  • That's a good catch actually. Looking at the https://github.com/datejs/Datejs repository there is a more recent version of the date-en-US.js at least. Ignore the front page readme! The problem goes away with the latest version because the now() function is no longer in date.js. :) – Richard Nixon Aug 26 '20 at 08:22
  • 3
    Confirmed. I had the version of date.js from 2007, the most recent one from 2008 (https://github.com/datejs/Datejs/blob/master/build/date.js) corrects the issue. – gsxrboy73 Aug 27 '20 at 13:36
  • Had the exact same issue. Had been troubling me for days. – Richard Ding May 15 '21 at 19:17
2

I am also getting the same error in version 3.41, but after changing it to version 3.40, It works!

Arjun Yadav
  • 106
  • 6
  • 1
    This is only temporary workaround. Once Google deprecates version 3.40 (I believe it will happen in 3 months) you won't access it, so the error will come back. https://developers.google.com/maps/documentation/javascript/versions – xomena Aug 25 '20 at 11:04
  • @xomena I can confirm this. I ran into this incompatibility issue as well and version 3.40 is no longer available. The only solution was to update `date.js` to version from 2008. It was deleted along with the version 3.43 https://developers.google.com/maps/documentation/javascript/releases#3.43 – Josef Trejbal Jul 05 '23 at 11:21
2

Ran into this same issue in a Rails app, updating data.js to a more recent version fixed it. There's a more recent fork that's available here that fixed the issue for me: https://github.com/abritinthebay/datejs