Moment.js: Uncaught TypeError: Cannot read property 'defineLocale' of undefined at moment.js:13

Sean D picture Sean D · Jun 17, 2017 · Viewed 16k times · Source

When running the small html file below I see the following console log error:

moment.js:13 Uncaught TypeError: Cannot read property 'defineLocale' of undefined
    at moment.js:13
    at moment.js:9
    at moment.js:10

I have also tried replacing the reference to the local library with this CDN link: https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/af.js

Anyone know what this error is?

Answer

luisenrike picture luisenrike · Jun 17, 2017

It seems to be a problem with your version of moment.js. The script that you have is only for locale, you need to include the moment.js script:

https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
</head>

<body>
  <script>
    var now = moment()
    console.log(typeof moment.defineLocale)
  </script>
</body>

</html>