Moment-timezone: Uncaught TypeError: Cannot read property 'version' of undefined

Created on 1 Apr 2017  Â·  22Comments  Â·  Source: moment/moment-timezone

This is a problem i'm currently having using https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.11/moment-timezone.js

From what I can see, the moment-timezone on cdnjs is different from http://momentjs.com/downloads/moment-timezone.min.js

Most helpful comment

This should probably be clearer in the documentation.

All 22 comments

Also noticed using https://momentjs.com/downloads/moment-timezone.min.js does the same.

@Tarik-M The only way i've made it work is by browserify-ing the node.js version.

Getting the same error.

@Haskaalo Yeah that sucks, I'm just using it for my website so I just linked it. Seems like a bigger process to get it to work otherwise.

This occurs if you have moment-timezone loaded but you haven't loaded any data. The version number is in the data file. If you use one of the "with-data" files, you won't have this issue.

@mpalomino - If you can reproduce in a jsfiddle, please do.

@kby799 - If you can reproduce in a jsfiddle, please do.

@mj1856 Sorry, I found my problem, didn't download moment.min.js packet. I thought it would be part of the moment-timezone-with-data-2012-2022.min.js.

Right. You need Moment, Moment-Timezone, and some data. Moment-Timezone doesn't include Moment - it's an add-on.

This should probably be clearer in the documentation.

Hi, I'm having trouble getting started with moment. Thanks in advance for your help

Here is the jsfiddle for it: https://jsfiddle.net/48prsv9u/

Here is the code. It's all in one html file.

Test.html

<script src="https://github.com/moment/moment-timezone/blob/develop/builds/moment-timezone-with-data-2012-2022.min.js"></script>
<script src="https://github.com/moment/moment-timezone/blob/develop/builds/moment-timezone-with-data.min.js"></script>
<script src="https://github.com/moment/moment-timezone/blob/develop/builds/moment-timezone.min.js"></script>

This is start of script
<script>
moment(new Date('jan 27, 1992'));
document.write(moment.utc(new Date()).local().format());
document.write(moment.utc('Sun Oct 01 2017 14:43:34 GMT-0400').local().format());
</script>
end1

@andyslater - you are missing moment.js. You have to load that, along with the moment-time-zone-with-data.js.

From the official docs:

Browser

<script src="moment.js"></script>
<script src="moment-timezone-with-data.js"></script>

When using Moment Timezone in the browser, you will need to load the data as well as the library.

I think this is confusing because the moment-timezone page (https://momentjs.com/timezone/) doesn't link to anything called moment.js; there's moment-timezone (and the minified versions) and the moment-timezone-with-data libraries, but doing the obvious curl -O on those files and then adding two script tag still results in the error originally reported in this issue, and the comments in this issue make it seem like you need to download moment-timezone.js and moment-timezone-with-data.js.

I got to https://momentjs.com/timezone/ via Google, and didn't see the main moment.js page until just now, after 15 minutes of trying to fix this problem. Maybe add a link to moment.js in Download section of https://momentjs.com/timezone/ to help those who get their via google?

Same error anyway (webpack):

import _moment from 'moment';
import moment from 'moment-timezone';
moment-timezone.js?1dcc:27 Uncaught TypeError: Cannot read property 'version' of undefined
    at eval (moment-timezone.js?1dcc:27)
    at eval (moment-timezone.js?1dcc:16)
    at Object.eval (moment-timezone.js?1dcc:18)
    at eval (moment-timezone.js:629)
    at Object../node_modules/moment-timezone/moment-timezone.js (vendor.js?89ef3235596e7255be02:15820)
    at __webpack_require__ (vendor.js?89ef3235596e7255be02:21)
    at eval (index.js?ba86:1)
    at Object../node_modules/moment-timezone/index.js (vendor.js?89ef3235596e7255be02:15807)
    at __webpack_require__ (vendor.js?89ef3235596e7255be02:21)
    at eval (Datetime.js:10)

Can you try download a fresh moment.js?

Same problem with the latest files, versions detailed below. I would agree with the other comments that it's not immediately clear which files should be loaded and in which order. I load onto the page in the following order:

  1. moment.min.js v2.21.0
  2. moment-timezone.min.js v0.5.14-2017c
  3. moment-timezone-with-data-2012-2022.min.js v0.5.14-2017c

and receive the 'version' error message.

If I don't include moment-timezone.min.js per the documentation, then I get

TypeError: moment(...).tz is not a function at…

Did this get resolved? I pull the dev and master branchs and have the same issue with 'version' of undefined.

Still happening on the following versions:

"moment": "^2.24.0",
"moment-timezone": "^0.5.26",

Guys, I solved this by adding moment script to my HTML page.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ciaoben picture ciaoben  Â·  3Comments

jishaal picture jishaal  Â·  6Comments

mj1856 picture mj1856  Â·  5Comments

ghost picture ghost  Â·  4Comments

guidsen picture guidsen  Â·  4Comments