27

I have installed react-moment 'npm i react-moment'. It is installed in the directory node_modules and dependency added in the package.json file. Every thing is correct. But when I import

import Moment from 'react-moment'

then it shows

Module not found: Can't resolve 'moment' in 'node_modules\react-moment\dist'

But there is nothing wrong with this directory, I haven't modified the files inside react-moment directory in node_modules. Just after installing the package, when I import the package

import Moment from 'react-moment'

Then it shows the error.

1
  • 4
    It looks like you have to npm i moment too. Commented Jul 28, 2020 at 14:58

5 Answers 5

52

moment is a peer dependency of react-moment, which mean you have to install moment in you project as well (it doesn't ship with its own version of moment).

npm i --save moment

Sign up to request clarification or add additional context in comments.

Comments

6

Worked for me:

  1. npm install --save moment
  2. npm install --save react-moment
  3. npm install --save moment-timezone

1 Comment

Anyone knows why the installation takes longer than usual?
2

I sorted it out by adding the '--legacy-peer-deps' argument to the end of the command as the error message shows:

npm ERR! Conflicting peer dependency: @angular/[email protected]
npm ERR! node_modules/@angular/common
npm ERR!   peer @angular/common@">=13.0.0 <14.0.0" from @ng-select/[email protected]
npm ERR!   node_modules/@ng-select/ng-select
npm ERR!     @ng-select/ng-select@"^8.0.0" from @ng-matero/[email protected]
npm ERR!     node_modules/@ng-matero/extensions
npm ERR!       @ng-matero/extensions@"^13.1.0" from the root project
npm ERR!     @ng-select/ng-select@"^8.1.1" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/yimin/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/yimin/.npm/_logs/2022-12-01T14_08_17_585Z-debug-0.log
npm install --save moment --legacy-peer-deps

Comments

0

I was having same issue with reac-datetime package and this one worked for me:

npm install --save moment

Comments

-2

If you are working with Timezone features make sure that you have installed the timezone package as well. if not paste the below npm code.

npm install --save moment-timezone

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.