How To Solve Module Not Found: Can’t Resolve ‘Moment’ Error

Module not found: Can't resolve 'moment' error

This article will show you how to fix Module not found: Can’t resolve ‘moment’ error by installing react-moment library or checking project dependencies.

What causes the Module not found: Can’t resolve ‘moment’ error? 

First, we have to find out what the react-moment library is and why this module’s missing error occurs.

React-moment is a React component library for formatting date objects, it has many uses for creating a custom date object by importing modules available in the library. The reason for the error is because you have not installed the library in your project or the compiled program does not recognize the library.


import React from "react";
import Moment from "react-moment";
const App = () => {
  return (
      <h2>Module not found: Can't resolve 'moment' error | LearnShareIT</h2>
      <Moment fromNow>2022-09-11T11:59-0500</Moment>
export default App;


As you can see webpack is not finding the Moment Module being imported into the component here so this error appears. How can we fix it? Let’s follow our next part to understand more.

How to fix the error Module not found: Can’t resolvemoment‘ error?

Install the “react-moment” method

Because webpack is not resolving the “react-moment” library, the easiest way is to reinstall this library with either install with npm or yarn depending on which one you are using.


npm i react-moment
yarn add react-moment

After installing the library, you will run the project again by running the command npm start and see the results:

You can easily calculate when the date object is added with the Moment module imported from the react-moment library after installing it. Or you can refer to the method below.

Checking project dependencies

In this way, you will check the dependencies in the package.json file to see if your project has enough libraries and the correct version of react-moment.

 "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-moment": "^1.1.2",

You can see that at the time I posted this article, November 2022, the version of the library is 1.1.2, which is why webpack has recognized the library. And if you have a problem getting the same version as mine then you should go to the react-moment homepage to see how much the library is up to. Good luck!


To summarize, the article has shown you how to fix the Module not found: Can’t resolve ‘moment’ error in some cases, but I recommend you install react- moment to be able to solve the problem most thoroughly. Hope you can fix it!

Maybe you are interested:

Leave a Reply

Your email address will not be published. Required fields are marked *