Moment: v2.25.1 - Can't resolve './locale'

Created on 6 May 2020  ·  8Comments  ·  Source: moment/moment

Describe the bug
When I build my React application, the build fails with an error.

./node_modules/moment/src/lib/locale/locales.js
Module not found: Can't resolve './locale' in '/Users/raravi/Programming/gitprojects/sudoku/node_modules/moment/src/lib/locale'

To Reproduce
Steps to reproduce the behavior:

  1. Add moment.js to a React application.
  2. Run npm start in the terminal
  3. Should see error pasted above.

Expected behavior
The React application should build without any errors from moment.

Desktop (please complete the following information):

  • OS: MacOS 10.15.4
  • Browser Brave 1.8.86

Moment-specific environment

  • The time zone setting of the machine the code is running on
  • The time and date at which the code was run
  • Other libraries in use (TypeScript, Immutable.js, etc)

Please run the following code in your environment and include the output:

console.log((new Date()).toString())
Wed May 06 2020 03:57:24 GMT+0200 (Central European Summer Time)
console.log((new Date()).toLocaleString())
06/05/2020, 03:57:24
console.log((new Date()).getTimezoneOffset())
-120
console.log(navigator.userAgent)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36
console.log(moment.version)
2.25.1

Most helpful comment

I have the same issue with my vue app. Also moved back to. 2.24.x

All 8 comments

We are having very similar problem since yesterday. Nothing changed on our end but the release of moment-2.25.2. We know see warnings like

WARNING in ./node_modules/moment/src/lib/locale/locales.js
Module not found: Error: Can't resolve './locale' in '/app/node_modules/moment/src/lib/locale'
 @ ./node_modules/moment/src/lib/locale/locales.js
 @ ./node_modules/moment/src/lib/locale/locale.js
 @ ./node_modules/moment/src/moment.js

The real problem is our UI generates a lot of errors

I come back to version 2.24.0 to fix this error

@Jerome2606 I've done the same, for now.

I have the same issue with my vue app. Also moved back to. 2.24.x

I used moment @ 2.25.3 without warning.

I'm using NextJS and I had to downgrade to 2.24.0 because I was not able to load other locales.
I tried almost everything with the require("/moment/locale/xxx") and the webpack plugin ContextReplacementPlugin from this example. I don't see any errors but it just does not load with this code :
javascript moment.locale(lang); momentTZ.updateLocale(lang, moment.localeData()._config); momentTZ.locale(lang);

Seems to work well in 2.25.3

Closing this issue, it's fixed in v2.25.3 !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RobinvanderVliet picture RobinvanderVliet  ·  3Comments

nikocraft picture nikocraft  ·  3Comments

slavafomin picture slavafomin  ·  3Comments

benhathaway picture benhathaway  ·  3Comments

alvarotrigo picture alvarotrigo  ·  3Comments