Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack Error: Cannot find module "./locale" after updating to 2.19.0 #4216

Closed
GautierT opened this issue Oct 10, 2017 · 153 comments
Closed

Webpack Error: Cannot find module "./locale" after updating to 2.19.0 #4216

GautierT opened this issue Oct 10, 2017 · 153 comments

Comments

@GautierT
Copy link

GautierT commented Oct 10, 2017

Edit: If you set your dependency to 2.18.1, everything will be fine. We are coordinating with some other libraries to find a permanent solution
Edit 2 : Set "moment": "2.18.1" in your package.json
Edit 3: We believe this is fixed.

Hello.
Using create-react-app. After updating moment to 2.19.0 i have this error on load :

Error: Cannot find module "./locale"
-> 9 stack frames were collapsed.
./src/utils/Utils.js
src/utils/Utils.js:1

1 | import moment from 'moment'

@GautierT GautierT changed the title Error: Cannot find module "./locale" after updating to 2.19.0 [React] Error: Cannot find module "./locale" after updating to 2.19.0 Oct 10, 2017
@AleshaOleg
Copy link

AleshaOleg commented Oct 10, 2017

I have the same, confirming this error.

@kasparasg
Copy link

same here

@silvioiannone
Copy link

Can confirm:

This relative module was not found:

* ./locale in ./node_modules/moment/src/lib/locale/locales.js

@ichernev
Copy link
Contributor

OK, we'll look into this, but it won't be very quick.

We changed the name of the require function, if someone can see/investigate if its linked to:

#4213
#4214

@patricksteenks
Copy link

Same problem here. Would downgrading fix the problem?

@sonaye
Copy link

sonaye commented Oct 10, 2017

Same here, broke multiple apps that I work on.

@GautierT
Copy link
Author

@patricksteenks : yes. Fix like this in you package.json "moment": "2.18.1"

@AleshaOleg
Copy link

@ichernev hey, but I'm using locale without importing. Just using import moment from 'moment' and use like this moment(date).locale('uk').format('ddd'). As I understood you changed import to locale. How I can fix this in my case?

@elliotleelewis
Copy link

Same issue on Angular-CLI built project

@KittyGiraudel
Copy link

Confirmed.

@rdzar
Copy link

rdzar commented Oct 10, 2017

VueJS 2 Webpack builds impacted too. Temp fix is as GautierT suggested (downgrade momentjs)

package.json (issue with moment-timezone dep on moment 2.19)

    "moment": "2.18.1",
    "moment-timezone": "^0.5.13",

package.json (issue in general)

    "moment": "2.18.1"

@knaos
Copy link

knaos commented Oct 10, 2017

I can confirm this is also happening!

@salihsagdilek
Copy link

salihsagdilek commented Oct 10, 2017

i can confirm.
package.json

"moment": "2.18.1"

@renedx just this line enough

@egavard
Copy link

egavard commented Oct 10, 2017

Same in an Angular 4 application.
Just downgraded to 2.18.1 (strict version number in package.json)

@wulfsberg
Copy link

Got hit by this as well. I suspect it is webpack doing some magic to recognize the dynamic "require", and can no longer recognize it under the new name, and thus the locales never get bundled into the package.

(Incidentally, this whole situation sounds an awful lot like exactly what ES6 dynamic imports are for. We can dream :-)

@Feverqwe
Copy link

Feverqwe commented Oct 10, 2017

I use in webpack from this page

new IgnorePlugin(/^\.\/locale$/, /moment$/)

Now remove it

And in require

const moment = require('moment');

Now

const moment = require('moment').default;

@GautierT GautierT changed the title [React] Error: Cannot find module "./locale" after updating to 2.19.0 [React/Webpack/Angular] Error: Cannot find module "./locale" after updating to 2.19.0 Oct 10, 2017
@wulfsberg
Copy link

Strictly speaking, I think the Angular connection is simply because most Angular projects use Angular-CLI, which internally uses Webpack. But it may be related to some specific Webpack configuration in that stack.
It does seem to be a fairly general bundling problem, though.

@TomMettam
Copy link

Repent, repent, doomsday is here!

thibautRe pushed a commit to fyndiq/fyndiq-ui that referenced this issue Oct 10, 2017
@kud
Copy link

kud commented Oct 10, 2017

Same here.

import moment from "moment"
import "moment/locale/fr"
moment.locale("fr")
WARNING in ./node_modules/moment/src/lib/locale/locales.js
Module not found: Error: Can't resolve './locale' in '/Users/kud/Projects/_contexte/lois-webapp/node_modules/moment/src/lib/locale'
 @ ./node_modules/moment/src/lib/locale/locales.js 65:16-60
 @ ./node_modules/moment/src/lib/locale/locale.js
 @ ./node_modules/moment/src/moment.js
 @ ./src/index.js

@aheissenberger
Copy link

Same here - I fixed it with a feature of yarn to overload the default settings of a package:

place this in your main package.json (adapt "moment-timezone" to the name of the package which does load moment if you do not directly load moment):

  "resolutions": {
    "moment-timezone/moment": "2.18.1"
  },

@gmatkowski
Copy link

gmatkowski commented Oct 10, 2017

just like an 10km asteroid .... same here ...

@maggiepint
Copy link
Member

MCVE: https://github.com/mj1856/moment-webpack-test

@arsyed04
Copy link

What is the ETA for fix?

@maggiepint
Copy link
Member

maggiepint commented Oct 10, 2017

Okay, here's where we're at:

  • If you set your dependency to 2.18.1, everything will be fine.
  • This is an issue with [critical] Rename dynamic require to avoid React Native crash #4213
  • I have engaged both the webpack and react native teams to talk about what fix will work for all parties
  • Because setting the dependency to 2.18.1 provides an easy mitigation, I do not at this time want to roll back. Instead, I would like to wait on feedback from Webpack and React Native to see if we can come to an agreement about what to do that will move this situation forward. For that reason, I don't have an ETA on a fix.
  • A MCVE can be found here: https://github.com/mj1856/moment-webpack-test

@SebastianMuniz
Copy link

I'm using version "2.25.1" and still happening!

@xlanor
Copy link

xlanor commented May 2, 2020

@m4mariaoni - that's because u installed without --save-dev, so you're changing the right part.

If you're still encountering this issue after locking moment to 2.24.0, nuke the moment folder from node_modules and reinstall your packages with npm install --save

@szdmacom
Copy link

szdmacom commented May 3, 2020

Thanks, @jolalla, I first tried downgrading the version but it didn't work for me. Finally adding the resolutions block showed some magic :)

For others who are are facing a similar issue with their react app. They can do the following 2 steps to resolve it.

In dependencies, replace
"moment": "^2.24.0",
with
"moment": "2.24.0",

And add the resolutions block in package.json

"resolutions": {
"moment": "2.24.0"
}

Works for me too! Thank you!! :D!thinks!

@FrozenHearth
Copy link

Thanks, @jolalla, I first tried downgrading the version but it didn't work for me. Finally adding the resolutions block showed some magic :)

For others who are are facing a similar issue with their react app. They can do the following 2 steps to resolve it.

In dependencies, replace
"moment": "^2.24.0",
with
"moment": "2.24.0",

And add the resolutions block in package.json

"resolutions": {
    "moment": "2.24.0"
  }

Replacing

"moment": "^2.24.0",

with

"moment": "2.24.0",

works for me! The usual,
rm -rf package-lock.json && node_modules

@Gustaf26
Copy link

Gustaf26 commented May 3, 2020

In spite of doing all above measures, still not working...

This is frustrating

@yiy0ung
Copy link

yiy0ung commented May 3, 2020

Previously created repositories were used moment 2.24.0 with React, and it's still working, but install moment2.24.0 now, doesn't working.... (I've tried all above measures, too)

What is the cause?

@agrohs
Copy link

agrohs commented May 3, 2020

I'd imagine you may have a ^2.24.0 instead of 2.24.0 somewhere in a package.json @wlsdud2194?

@Gustaf26
Copy link

Gustaf26 commented May 3, 2020

I don´t, and still the error keeps coming. It´s weird

@yiy0ung
Copy link

yiy0ung commented May 3, 2020

moment version is 2.24.0 in a package.json instead of ^2.24.0 that since I installed it.

I followed this process, one of the above measures

  1. add resolutions block
  2. remove node_modules directory and reinstall package from yarn.

works for me, but don't know why working...😂

Thank you for your interest : ) @agrohs

@dons20
Copy link

dons20 commented May 4, 2020

Had to downgrade from ^2.25.1 to 2.24.0 to fix the issue

@dex-labs
Copy link

dex-labs commented May 4, 2020

I don´t, and still the error keeps coming. It´s weird

Try running npm ls moment to see if any other module uses moment as well

@szdmacom
Copy link

szdmacom commented May 4, 2020 via email

@dinesh-dubey
Copy link

We are getting Webpack Error: Cannot find module "./locale" error. We are using 'react-redux-i18n' package in our project which has dependency on 'react-i18nify' and that in turn has dependency on 'moment'. Internally 'moment' is configured to use latest version which is causing this error.

npm

In dependencies
"react": "^16.8.1",
"moment": "2.24.0",
"moment-timezone": "^0.5.28",
"react-moment-proptypes": "^1.5.0",
"react-redux-i18n": "^1.9.3",
"react-redux": "^6.0.0",

Any help would be greatly appreciated.

@jasontll
Copy link

jasontll commented May 4, 2020

The latest patch 2.25.3 seems to have fixed it, update the momentjs version to: "moment": "^2.25.3" in package.json
Remove the node_modules folder, and run yarn install or npm install should do it.

@doug97703
Copy link

For those who've lost some confidence in moment, and don't want their apps to completely break from this issue happening again in the future - I switched a medium-sized codebase over to luxon without too much trouble.

@Gustaf26
Copy link

Gustaf26 commented May 9, 2020

Thank you people...

I changed version to 24.0 and added the "resolutions": { "moment": "2.24.0" } and ran npm install

Then it seemed to work again (working with React, by the way).

Cheers!

@dinesh-dubey
Copy link

The latest patch 2.25.3 seems to have fixed it, update the momentjs version to: "moment": "^2.25.3" in package.json
Remove the node_modules folder, and run yarn install or npm install should do it.

Thank you @jasontll , it works for me

@hugoh59
Copy link

hugoh59 commented May 25, 2020

None of these solutions worked for me today.

@DeepakpOctal
Copy link

DeepakpOctal commented May 28, 2020

Been doing this for hours on my react app
with npm.

1. I updated from moment  2.17 to 2.24

2. I added the resolutions as adviced above - `"devDependencies": {...},"resolutions": { "moment": "2.24.0"   }` to package.json

3. Changed to yarn by doing the following. `rm -rf node_modules package-lock.json && yarn`
   Thanks a lot guys

its also worked for guys thanks a lot :-)

@Gkiokan
Copy link

Gkiokan commented Jun 20, 2020

I run also in this trouble. I've fixed it with the latest version as of "moment": "^2.26.0"

@sbaechler
Copy link

With 2.29.1 dynamic import of locales still does not work with webpack and the create-react-app config (worked with 2.24).

A workaround is to add a new Javascript file in your project that just imports the one locale and then dynamically import that file.

@Welle77
Copy link

Welle77 commented Jul 28, 2021

I added a metro.config.js file after upgrading, which didn't allow the files to be loaded correctly. Removed the file and it works again.

rjshrjndrn added a commit to rjshrjndrn/sunbird-portal that referenced this issue Dec 23, 2021
Ref: moment/moment#4216 (comment)

Signed-off-by: Rajesh Rajendran <rjshrjndrn@gmail.com>
rjshrjndrn added a commit to rjshrjndrn/sunbird-portal that referenced this issue Dec 23, 2021
Ref: moment/moment#4216 (comment)

Signed-off-by: Rajesh Rajendran <rjshrjndrn@gmail.com>
@dimaslanjaka
Copy link

i was changed aliasesRequire in moment/min/moment-with-locales.js from

            require('./locale/' + name);
            // because defineLocale currently also sets the global locale, we
            // want to undo that for lazy loaded locales

to

            require('moment/locale/' + name);
            // because defineLocale currently also sets the global locale, we
            // want to undo that for lazy loaded locales

and now works without error No Module ./locale while compiling and on production

@Edo90
Copy link

Edo90 commented Dec 16, 2023

Thanks, @jolalla, I first tried downgrading the version but it didn't work for me. Finally adding the resolutions block showed some magic :)
For others who are are facing a similar issue with their react app. They can do the following 2 steps to resolve it.
In dependencies, replace
"moment": "^2.24.0",
with
"moment": "2.24.0",
And add the resolutions block in package.json

"resolutions": {
    "moment": "2.24.0"
  }

Replacing

"moment": "^2.24.0",

with

"moment": "2.24.0",

works for me! The usual, rm -rf package-lock.json && node_modules

It worked perfect for me, thank you so much. Keep in mind guys that if you are using workspaces, you should remove de package-lock.json and node_modules from every directory that could use the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests