Moment.js: Uncaught TypeError: Cannot read the defineLocale property in undefined at the moment. Js: 13

When I run a 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>
Run codeHide result

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

Does anyone know what this error is?

+4
source share
1 answer

There seems to be a problem with your version moment.js. The script you have is just for locale, you need to include the moment.jsscript:

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>
Run codeHide result
+10
source

Source: https://habr.com/ru/post/1679500/


All Articles