Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 407
Prasanga Thapaliya Avatar asked Jul 28 '20 14:07

Prasanga Thapaliya


2 Answers

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

like image 118
known-as-bmf Avatar answered Nov 16 '22 11:11

known-as-bmf


Worked for me:

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

:)

like image 43
Lucas Dias Procópio Mercês Avatar answered Nov 16 '22 12:11

Lucas Dias Procópio Mercês