moment: Uncaught Error: Cannot find module './locale'
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.<anonymous> (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.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 42
- Comments: 69 (4 by maintainers)
Commits related to this issue
- #6 Account Add UI Part, TODO: API and debug 1. Add Account UI 2. Downgrade moment to 2.24.0 https://github.com/moment/moment/issues/5484 3. Remove package-lock.json — committed to duocun/duocun-backoffice by deleted user 4 years ago
- Fix Moment.js bug by downgrading See: https://github.com/moment/moment/issues/5484 — committed to the-commons-project/commonhealth-data-map by hectcastro 4 years ago
- 锁定moment版本号 修复新版本moment(2.25.0 / 2.25.1)找不到./locale package bug https://github.com/moment/moment/issues/5484 — committed to jzyds/HoServer by jzyds 4 years ago
- Chaning version of moment to a fixed 2.24.0 - Changed version because ^ bumbed it to 2.25.1 which throws an error described here: https://github.com/moment/moment/issues/5484 — committed to keep-network/keep-core by dimpar 4 years ago
- Fix the version of moment, there seams to be a bug https://github.com/moment/moment/issues/5484 — committed to AtomsProject/Atoms.Time by AdamCLarsen 4 years ago
- Changing version of momemnt - Changed to 2.24.0 because having ^ updated it to 2.25.1 which throws an error. There is an issue on github: https://github.com/moment/moment/issues/5484 — committed to keep-network/keep-core by dimpar 4 years ago
- attempt to fix dependencies for server issue with moment locale https://github.com/moment/moment/issues/5484 — committed to p2bauer/flightplan by deleted user 4 years ago
- upgrade moment to ^2.25.3 fix https://github.com/moment/moment/issues/5484# — committed to FightPandemics/FightPandemics by joshmorel 4 years ago
- upgrade moment to ^2.25.3 fix https://github.com/moment/moment/issues/5484# — committed to FightPandemics/FightPandemics by joshmorel 4 years ago
- [pkg] Remove module property as it is causing issues with webpack — committed to moment/moment by ichernev 4 years ago
- upgrade moment to ^2.25.3 fix https://github.com/moment/moment/issues/5484# — committed to FightPandemics/FightPandemics by joshmorel 4 years ago
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.
if you use yarn, add resolutions block to package.json to override versions of sub-dependency, it work for me
I’ve updated to the version
2.25.1
, but I still got the error.But maybe I’m doing something wrong. Can anybody confirm that this error has disappeared in 2.25.1 ?
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:So inside
antd/package.json
andrc-picker/package.json
independencies
:And run
npm i
TWICE. Do not know why need twice, but it only works after twice.2.25.3 is out without
module
.Any news from the devs?
i’ve had to revert to “2.24.0”, moment can’t find ‘./locale’
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.This works for me, I am using create-react-app. // in webpack.config.js
Same problem here after upgrading to 2.25.0 and 2.25.1. The only solution that worked for me is downgrade to 2.24.0
Why are these issues closed…this is wreaking havoc
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!?!?!
Handling of require was reverted to 2.24.0 behavior.
Fixed in 2.25.1.
this works perfectly for me : https://github.com/moment/moment/issues/4216#issuecomment-622453248
Same problem here with moment version
2.25.0
in one of my gatsby-based projects:With moment
2.24.0
there is no such issue.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.
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 ^