Create-React Application with JS Moment: Cannot find the module "./locale"

Just launched npm updatein my web application, and now Moment JS appears with an error with the following message:

Error: Cannot find module "./locale"
\node_modules\moment\src\lib\moment\prototype.js:1
> 1 | import { Moment } from './constructor';

I don’t know what version of Moment JS I had before my update, but my application has been working for several months.

I created another responsive application and ran npm install moment --saveand modified the source code to display the time, and ended up with the same error described above.

Not sure if there is a fault-tolerant way to integrate Moment JS using the Create-React-App, which is not currently used to manage webpack settings on its own, but I really don't want to. Does anyone else see these problems or have success? If so, a short entry will go the way to help.

+7
source share
3 answers

It looks like this has already been identified as a problem for Moment JS version 2.19. If you upgraded to version 2.19, run npm install moment@2.18.1to go back to the previous version until it is fixed!

See the thread: https://github.com/moment/moment/issues/4216

+5
source

, , , . , , , .

-. webpack.config.js. , -:

YOURAPPNAME/node-modules/webpack/

, , webpack.config.js, . , webpack.config.js.

module.exports = {
    resolve: {
        alias: {
            moment$: 'moment/moment.js'
        }
    }
};

index.js ( ) :

import moment from 'moment'

. :

var tomorrow = moment().add(1, "day")
+2

An application created using the Create React App and using Moment 2.24.0 is as follows:

import moment from 'moment';
import 'moment/min/locales';

Instead of importing moment-with-localesdirectly. In addition, it is also possible to import only the necessary locales:

import moment from 'moment';
import 'moment/locale/fr';
import 'moment/locale/ru';
0
source

Source: https://habr.com/ru/post/1687253/


All Articles