Uncaught ReferenceError: Moment is Not Defined - Solved
By Henri Parviainen
If you've ever encountered the dreaded
There are a few different ways to fix the
Uncaught ReferenceError: moment is not defined error. Let's take a look at each of them.
The most straightforward solution is to make sure the Moment.js library is properly included in your project. You can download the library from the official Moment.js website, or you can use a CDN to link to it.
Here's how you can include Moment.js via CDN in your HTML file:
If you encountered the problem on
node.js install moment via npm:
npm install moment
import moment from "moment";
Uncaught ReferenceError: moment is not defined error.
If you've tried the above solutions and are still getting the
Uncaught ReferenceError: moment is not defined error, it's time to look at external factors. For example, if you're using a CDN to link to the Moment.js library, check if the CDN is down. You can do this by visiting the URL in your browser and seeing if it loads correctly.
If you're using a CDN, you can also try using a different one to see if that resolves the issue. You can find a list of CDNs that host Moment.js on cdnjs.com.
Some browser extensions can also cause issues with Moment.js. Try disabling any extensions you have installed and see if that fixes the problem.
If you're still getting the
Uncaught ReferenceError: moment is not defined error, you might want to consider using a different library for date and time manipulation.
Moment.js is considered to be a legacy project in maintenance mode. The project maintainers have recommended that developers use a different library for new projects.