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

Uncaught Error: Cannot find module './locale' #5484

Closed
mau21mau opened this issue May 1, 2020 · 69 comments · Fixed by FightPandemics/FightPandemics#452
Closed

Uncaught Error: Cannot find module './locale' #5484

mau21mau opened this issue May 1, 2020 · 69 comments · Fixed by FightPandemics/FightPandemics#452

Comments

@mau21mau
Copy link

mau21mau commented May 1, 2020

Describe the bug
I get this error on chrome console after I build the production optimized build

Uncaught Error: Cannot find module './locale'
at 2.d0944550.chunk.js:1
at Module. (2.d0944550.chunk.js:1)
at f ((index):1)
at Module.837 (main.091f08fc.chunk.js:1)
at f ((index):1)
at Object.540 (main.091f08fc.chunk.js:1)
at f ((index):1)
at a ((index):1)
at Array.e [as push] ((index):1)
at main.091f08fc.chunk.js:1

This is my package.json

{
  "name": "sheetgo-front-end",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@allpro/react-router-pause": "^1.1.3",
    "@material-ui/core": "^4.4.2",
    "@material-ui/icons": "^4.5.1",
    "@material-ui/lab": "^4.0.0-alpha.26",
    "@material-ui/styles": "^4.4.1",
    "@material/icon-button": "^3.1.0",
    "@material/react-button": "^0.15.0",
    "@material/react-card": "^0.15.0",
    "@material/react-icon-button": "^0.15.0",
    "@material/react-material-icon": "^0.15.0",
    "@material/react-select": "^0.15.0",
    "@material/react-tab": "^0.15.0",
    "@mdi/js": "^3.4.93",
    "@mdi/react": "^1.1.0",
    "@stripe/react-stripe-js": "^1.1.0",
    "@stripe/stripe-js": "^1.2.0",
    "@svgr/webpack": "^4.1.0",
    "apexcharts": "^3.8.6",
    "axios": "^0.19.2",
    "browser-info": "^1.2.0",
    "chart.js": "^2.7.2",
    "classnames": "^2.2.6",
    "color-sort": "^0.0.1",
    "connected-react-router": "^6.5.2",
    "countup.js": "^1.9.3",
    "cra-append-sw": "^2.7.0",
    "filepond": "4.1.0",
    "filepond-plugin-file-validate-size": "2.1.1",
    "filepond-plugin-file-validate-type": "1.2.2",
    "form-serialize": "^0.7.2",
    "fuse.js": "^3.4.2",
    "history": "^4.10.1",
    "inputmask": "^4.0.0",
    "is-mobile": "^2.0.0",
    "jquery": "^3.3.1",
    "jquery-ui-sortable-npm": "^1.0.0",
    "js-cookie": "^2.2.0",
    "lodash": "^4.17.10",
    "markdown-to-jsx": "^6.10.3",
    "material-components-web": "^3.1.0",
    "material-ui-chip-input": "^1.0.0",
    "md5": "^2.2.1",
    "memoize-one": "^5.0.4",
    "moment": "^2.22.2",
    "moment-timezone": "^0.5.27",
    "onecolor": "^3.1.0",
    "p-queue": "^6.1.1",
    "payform": "^1.2.2",
    "promise-throttle": "^1.0.0",
    "prop-types": "^15.7.0",
    "query-string": "^6.5.0",
    "react": "^16.8.1",
    "react-apexcharts": "^1.3.3",
    "react-dom": "^16.8.1",
    "react-draggable": "4.2.0",
    "react-filepond": "7.0.1",
    "react-google-authorize": "^1.0.4",
    "react-hotjar": "^2.0.0",
    "react-id-swiper": "^1.6.8",
    "react-intl": "^2.5.0",
    "react-modal-video": "^1.2.3",
    "react-redux": "^7.1.1",
    "react-resizable": "^1.8.0",
    "react-router": "^5.1.2",
    "react-router-dom": "^5.1.2",
    "react-router-last-location": "^2.0.1",
    "react-scripts": "^2.1.4",
    "react-sizeme": "^2.5.2",
    "react-stripe-elements": "^4.0.0",
    "react-text-mask": "^5.4.3",
    "react-virtualized-auto-sizer": "^1.0.2",
    "react-vis-network": "^1.0.0",
    "react-window": "^1.8.1",
    "recompose": "^0.30.0",
    "redux": "^4.0.4",
    "redux-react-session": "^2.4.0",
    "redux-saga": "^1.1.1",
    "redux-thunk": "^2.3.0",
    "socket.io-client": "^2.3.0",
    "sort-by": "^1.2.0",
    "tether": "^1.4.4",
    "throttle-debounce": "^2.1.0",
    "url-loader": "^1.0.1"
  }

If I build locally with yarn for the dev version it works

To Reproduce
Steps to reproduce the behavior:
Build an app with those requirements. Should get that error on console.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

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())
console.log((new Date()).toLocaleString())
console.log((new Date()).getTimezoneOffset())
console.log(navigator.userAgent)
console.log(moment.version)

Additional context
Add any other context about the problem here.

@manosriram
Copy link

Exactly. I just faced this error and saw that they just pushed a new version hours ago.

@rilyu
Copy link

rilyu commented May 1, 2020

if you use yarn, add resolutions block to package.json to override versions of sub-dependency, it work for me

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

@aeroxy
Copy link

aeroxy commented May 1, 2020

Same here!

@aeroxy
Copy link

aeroxy commented May 1, 2020

Also 2.24.0 still has the warning: ./node_modules/chart.js/node_modules/moment/src/lib/locale/locales.js Critical dependency: the request of a dependency is an expression

@brianshen1990
Copy link

Just reproduce this problem

brianshen1990 pushed a commit to duocun/duocun-backoffice that referenced this issue May 1, 2020
1. Add Account UI
2. Downgrade moment to 2.24.0 moment/moment#5484
3. Remove package-lock.json
@nltb99
Copy link

nltb99 commented May 1, 2020

Same too!

@veryStarters
Copy link

  • 1

@SaadKhanBackendDeveloper

Same issue,

Fixed by removing carret sign before version number. Package.json entry now looks like:
"moment": "2.24.0"

It looks like a bug from the new version.

@wktdev
Copy link

wktdev commented May 1, 2020

Tonight I installed Jest and it created a problem and I was instructed to remove any yarn.lock and package.lock files along with my modules folder and do yarn install or npm install. When I did yarn install I received the error mentioned in this thread - the page that appeared said the error was a webpack error and pointed to moment-timezone. When I removed my lock files , module folder and reinstalled using npm install (instead of yarn install) - everything worked.In short when I used a different package manager command it changed the outcome.

@kothari775
Copy link

Please remove ^ in package.json this way its worked for me 👍

strange such incident happened early this week due to is-promise library there also issue like ^ need to remove. I believe people will now more or less do for all package.json strict version instead of ^

@purefan
Copy link

purefan commented May 1, 2020

Tried removing the caret from package.json and running + rm -rf node_modules + yarn and I still get this problem when running webpack

@ajayar
Copy link

ajayar commented May 1, 2020

I am using moment-timezone, and it defaults to 2.25. removing caret makes no difference

@JackLian
Copy link

JackLian commented May 1, 2020

Same here!

@constlhq
Copy link

constlhq commented May 1, 2020

This works for me, I am using create-react-app.
// in webpack.config.js

plugins: [
...
// new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// replace the line above with below, regex to match the locale you want to use
new webpack.ContextReplacementPlugin(/moment[\/\\]locale/,  /(en|zh-cn)\.js/)
...
]

@JKarlavige
Copy link

It appears there's an issue with their latest version. I had to revert back to "2.24.0" without the "^" and that allowed my sites to build.

@drmats
Copy link

drmats commented May 1, 2020

Same problem here with moment version 2.25.0 in one of my gatsby-based projects:

Cannot find module './locale'                              
                                                                                                                                              
                                                                                                                                              
> 1 | import { Moment } from './constructor';                                                                                                 
    | ^                                                                                                                                       
  2 |                                                                                                                                         
  3 | var proto = Moment.prototype;                                                                                                           
  4 |                                                                                                                                         
                                                                                                                                              
                                                                                                                                              
  WebpackError: Cannot find module './locale'                                                                                                 
                                                                                                                                              
  - prototype.js:1 webpackMissingModule                                                                                                       
    node_modules/moment/src/lib/moment/prototype.js:1:1                                                                                       
                                                                                                                                              
  - prototype.js:1 Module../node_modules/moment/src/lib/moment/prototype.js                                                                   
    node_modules/moment/src/lib/moment/prototype.js:1:1                                                                                       
                                                                                                                                              
  - moment.js:1 Module../node_modules/moment/src/lib/moment/moment.js                                                                         
    node_modules/moment/src/lib/moment/moment.js:1:1                                                                                          
                                                                                                                                              
  - moment.js:1 Module../node_modules/moment/src/moment.js                                                                                    
    node_modules/moment/src/moment.js:1:1

With moment 2.24.0 there is no such issue.

@ichernev
Copy link
Contributor

ichernev commented May 1, 2020

Can someone provide a minimal (non)-working example so this can be investigated?

@paulohpf
Copy link

paulohpf commented May 1, 2020

i've had to revert to "2.24.0", moment can't find './locale'

@guigeekz
Copy link

guigeekz commented May 1, 2020

this works perfectly for me : #4216 (comment)

@NathanChannon
Copy link

NathanChannon commented May 1, 2020

Can someone provide a minimal (non)-working example so this can be investigated?

Hey @ichernev - please find attached. Just run npm install, and npm start :)

issue5484.zip

@ichernev
Copy link
Contributor

ichernev commented May 1, 2020

Handling of require was reverted to 2.24.0 behavior.

Fixed in 2.25.1.

@ichernev ichernev closed this as completed May 1, 2020
@bessarabov
Copy link

I've updated to the version 2.25.1, but I still got the error.

prototype.js:1 Uncaught Error: Cannot find module './locale'
    at webpackMissingModule (prototype.js:1)
    at Module../node_modules/moment/src/lib/moment/prototype.js (prototype.js:1)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Module../node_modules/moment/src/lib/moment/moment.js (moment.js:1)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Module../node_modules/moment/src/moment.js (moment.js:1)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Module../src/Menu.js (Home.js:186)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Module../src/App.js (Add.js:157)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Module../src/index.js (index.css?02e3:45)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Object.0 (serviceWorker.js:135)
    at __webpack_require__ (bootstrap:782)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1

But maybe I'm doing something wrong. Can anybody confirm that this error has disappeared in 2.25.1 ?

@puopg
Copy link

puopg commented May 1, 2020

Same issue for me and moment-timezone. Ive tried forcing 2.24.0, but still same issue since im guessing moment-timezone uses the latest?

@stranzhay
Copy link

Still getting the error

hectcastro added a commit to the-commons-project/commonhealth-data-map that referenced this issue May 1, 2020
@Fi1osof
Copy link

Fi1osof commented May 1, 2020

@strange1120 is moment@2.25.1?
If you use yarn, try yarn why moment to show installed deps.

@NathanChannon
Copy link

@ichernev Sorry, I can confirm 2.25.1 throws the same error. Using the app I uploaded previously, and a clean node_modules/package-lock.json, I can see the version is 2.25.1 but still throws.

@pagoru
Copy link

pagoru commented May 4, 2020

Having the issue with the 2.24, trying to put the "resolutions"... but I didn't update to 2.25, what's wrong? It was working on Thursday.

@namazbaev
Copy link

Downgrading to 2.24.0 worked for me. Remove the ^ with 2.24.0.
Also manually updated all the moment dependencies to 2.24.0 in package-lock.json as well.

Thanks worked! There is a problem with Yarn. Worked with Npm

@pagoru
Copy link

pagoru commented May 4, 2020

Until the fix will be released, as was mentioned by @saadzr, you can temprorary just assign moment to "2.24.0" version. Remove carret: "^".

For those who does not know how to do it. Find the packages which use moment: npm ls moment. You will probably see:

└─┬ antd@4.2.0
  ├── moment@2.25.1 
  └─┬ rc-picker@1.4.10
    └── moment@2.25.1  deduped

So inside antd/package.json and rc-picker/package.json in dependencies:

"moment": "^2.24.0", -> "moment": "2.24.0"

And run npm i TWICE. Do not know why need twice, but it only works after twice.

Working! <3

@purefan
Copy link

purefan commented May 4, 2020

yarn remove + yarn add moment installed version 2.25.2 which builds fine for me

@namazbaev
Copy link

yarn remove + yarn add moment installed version 2.25.2 which builds fine for me

Wouldn’t that be a problem in this version?

@purefan
Copy link

purefan commented May 4, 2020

@Shakxzod-Namazbaev I think the original problem was with version 2.25.0, some people reported that the same problem happens in 2.25.1, others have mentioned that downgrading to 2.24 works for them. In my case version 2.25.2 seems to work, so maybe downgrading is not needed

@namazbaev
Copy link

@Shakxzod-Namazbaev I think the original problem was with version 2.25.0, some people reported that the same problem happens in 2.25.1, others have mentioned that downgrading to 2.24 works for them. In my case version 2.25.2 seems to work, so maybe downgrading is not needed

So you don't have a problem with version 2.25.2 right now, right?

dimpar added a commit to keep-network/keep-core that referenced this issue May 4, 2020
- Changed to 2.24.0 because having ^ updated it to 2.25.1 which throws
an error. There is an issue on github: moment/moment#5484
@purefan
Copy link

purefan commented May 4, 2020

@Shakxzod-Namazbaev exactly, 2.25.2 works fine for me.

@drmats
Copy link

drmats commented May 4, 2020

I can confirm - moment 2.25.2 works also for me.

@NathanChannon
Copy link

NathanChannon commented May 4, 2020

I think 2.25.2 is OK in standalone form but in packaged-managed form, it's still broken (webpack in my case where moment is a dependency of moment-timezone).

2.24.0 is still the one for people using webpack and other moment-dependant packages.

@drmats
Copy link

drmats commented May 4, 2020

ver. 2.25.2 works for me in package-managed form - webpack configured in a gatsby-based project (ver. 2.25.0 didn't):

relevant package.json lines:

dependencies: {
    ...
    "moment": "^2.25.2",
    ...
}

I'm not using moment-timezone though.

@agrohs
Copy link

agrohs commented May 4, 2020

So crazy that this Issue report is still sitting as Closed with so many people affected and the only "solution" so far is to downgrade to an old version!?!?!

@bessarabov
Copy link

@ichernev Thank you! Updating to 2.25.2 fixes this issue for me!

--- a/front/package.json
+++ b/front/package.json
@@ -5,7 +5,7 @@
   "dependencies": {
-    "moment": "^2.22.2",
+    "moment": "^2.25.2",

@drmats
Copy link

drmats commented May 4, 2020

OK. I praised too early. Although with moment ver. 2.25.2 webpack is able to produce working bundle without errors, but importing locale doesn't work anymore - looks like it's being ignored (perhaps this has something to do with sideEffects / tree shaking?).

E.g.:

import moment from "moment"
import "moment/locale/pl"

// set global 'moment' locale (polish)
moment.locale("pl")

// ... somewhere later
console.log(moment().format("DD MMMM YYYY HH:mm:ss"))

With version 2.25.2 output is 04 May 2020 16:38:15, which is incorrect, as it should be
04 maja 2020 16:38:58.

So, version 2.24.0 is still the last working one.

@shubhamagarwal
Copy link

shubhamagarwal commented May 4, 2020

I faced the same issue, removing carrot from the version fixed this.

Like this in your package.json file --- "moment": "2.24.0"

Version : 2.24.0

@ichernev
Copy link
Contributor

ichernev commented May 4, 2020

Well, I was testing locally, and I can't really tell why, but if the is a package.json property module then it's broken. If there is only jsnext:main it is working. This relates to locale files not being loaded properly, while still included in the bundle.

So this "modern" module property that suppersedes jsnext:main is not just a rename, or an alt name. It has some hidden agenda that is not well advertised.

@ichernev
Copy link
Contributor

ichernev commented May 4, 2020

2.25.3 is out without module.

@drmats
Copy link

drmats commented May 4, 2020

@ichernev - thanks! I can confirm version 2.25.3 works (webpack is able to produce bundle without errors and including/setting locale works as expected).

@imatteh
Copy link

imatteh commented May 4, 2020

Fixes in 2.25.3 for me.

@Fhyrel
Copy link

Fhyrel commented Aug 3, 2020

Same issue,

Fixed by removing carret sign before version number. Package.json entry now looks like:
"moment": "2.24.0"

It looks like a bug from the new version.

After that works!

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

Successfully merging a pull request may close this issue.