Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>

    <script src="../scripts/libraries/moment.js"></script>

</head>

<body>


<script>
  var now = moment()
  console.log(now);
</script>

</body>
</html>

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?

like image 369
Sean D Avatar asked Jun 17 '17 00:06

Sean D


1 Answers

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>
like image 77
luisenrike Avatar answered Sep 17 '22 14:09

luisenrike