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.
Code:
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;
Output:

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 resolve ‘moment‘ 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.
Terminal:
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!
Summary
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:
- Module not found: Can’t resolve @babel/runtime/helpers
- Module not found: Can’t resolve ‘jquery’ in React
- Module not found: Can’t resolve ‘axios’ in React

Hi, my name’s Nathaniel Kirk. I’m interested in learning and sharing knowledge about programming languages. My strengths are C, C++, Python, HTML, CSS, Javascript, and Reactjs. If you have difficulty with them, don’t worry. I’m here to support you.
Name of the university: PTIT
Major: IT
Programming Languages: C, C++, Python, HTML, CSS, Javascript, Reactjs