moment: Can't resolve './locale'
Describe the bug
When I configure mainFields
of webpack, it outputs errors.
To Reproduce
Steps to reproduce the behavior:
-
Install moment@2.24.0
-
Modify webpack config file
{ resolve: { mainFields: ['module', 'jsnext:main', 'browser', 'main'], }, }
-
Use webpack to build bundles
-
Output some errors on console
WARNING in ./node_modules/moment/src/lib/locale/locales.js Module not found: Error: Can't resolve './locale' in '/home/user/workspace/portal/h5v2/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 @ ../modules/seed/h5v2/main.js
Expected behavior
Webpack build successfully.
Screenshots
I modified the highlight line below, webpack build successfully.
I think https://github.com/moment/moment/blob/develop/src/lib/locale/locales.js#L78 has some problem.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 16
- Comments: 42 (2 by maintainers)
Commits related to this issue
- [bugfix] Revert changes made for #5269 due to webpack warnings — committed to moment/moment by ichernev 4 years ago
- pin moment to ~2.24 (#1018) Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0`: * [5489](https://github.com/moment/moment/issues/5489) * [5472](https://github.com/moment/moment/iss... — committed to folio-org/ui-inventory by zburke 4 years ago
- Downgraded moment version because of issue #5472 https://github.com/moment/moment/issues/5472 — committed to tonix-tuft/tempusdominus-bootstrap by tonix-tuft 4 years ago
- STRIPES-678 resolve moment to v2.24.0 Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/momen... — committed to folio-org/platform-core by zburke 4 years ago
- STRIPES-678 resolve moment to v2.24.0 (#593) Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/momen... — committed to folio-org/platform-core by zburke 4 years ago
- STRIPES-678 pin moment to ~2.24 Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/moment/issu... — committed to folio-org/stripes-components by zburke 4 years ago
- STRIPES-678 pin moment to ~2.24 Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/moment/issu... — committed to folio-org/stripes-core by zburke 4 years ago
- STRIPES-678 pin moment to ~2.24 Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/moment/issu... — committed to folio-org/stripes-smart-components by zburke 4 years ago
- STRIPES-678 pin moment to ~2.24 (#1255) Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/m... — committed to folio-org/stripes-components by zburke 4 years ago
- STRIPES-678 pin moment to ~2.24 (#847) Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/mom... — committed to folio-org/stripes-core by zburke 4 years ago
- STRIPES-678 pin moment to ~2.24 (#795) Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/mo... — committed to folio-org/stripes-smart-components by zburke 4 years ago
- STRIPES-678 pin moment to ~2.24 Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/moment/issu... — committed to folio-org/ui-calendar by zburke 4 years ago
- STRIPES-678 pin moment to ~2.24 Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/moment/issu... — committed to folio-org/ui-checkout by zburke 4 years ago
- STRIPES-678 pin moment to ~2.24 Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/moment/issu... — committed to folio-org/ui-circulation by zburke 4 years ago
- STRIPES-678 pin moment to ~2.24 Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/moment/issu... — committed to folio-org/ui-eholdings by zburke 4 years ago
- Build 2.25.1 — committed to moment/moment by ichernev 4 years ago
- STRIPES-678 pin moment to ~2.24 Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/moment/issu... — committed to folio-org/ui-users by zburke 4 years ago
- [bugfix] Can't resolve './locale https://github.com/moment/moment/issues/5472 — committed to bluewings/react-genie-form by deleted user 4 years ago
- fix(dependencies): force Moment library version to 2.24.0 to prevent moment/moment#5472 — committed to remija/react-starter by remija 4 years ago
- STRIPES-678 pin moment to ~2.24 (#1290) Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0` ([5489](https://github.com/moment/moment/issues/5489), [5472](https://github.com/moment/mo... — committed to folio-org/ui-users by zburke 4 years ago
Continues with 2.25.1 too.
Downgrading to the previous minor version (
2.24.0
) works as usual:Same problem over here with 2.25.1!
Hello Guys! I faced the same issue from last few hours and finally I have resolved it through changing moment version.
Reason: moment release the new version 17 hours ago from 2.24.0 to 2.25.0
Solution: Step 1: change the versions
Step 2: If you are using yarn please add resolutions in your package.json file like this “dependencies” { “moment”: “2.24.0”, “moment-timezone”: “^0.5.28” }, “resolutions”: { “moment”: “2.24.0” },
Thank You.
These steps worked for me
Add to “scripts” node in package.json
I’m really surprised this was released with this broken. It breaks everyone’s web pack. Is there an instance for someone where this works properly? Are we not testing web pack builds?
same issue with 2.25.1
2.25.2 should address this. You might need to change your webpack configuration if you don’t want the locale files to be auto-bundled.
i was changed aliasesRequire in
moment/min/moment-with-locales.js
fromto
and now works without error
No Module ./locale
while compiling and on productionfacing the same issue. Latest moment version causing issues in many websites . moment team please fix it asap.
Yes, the problem is the version, Thank for your answer.
I’m continuing to see issues this morning. The build succeeds with no errors that I can see, however my application is not loading and the console is reporting:
I’m using
I’ve deleted my node_modules and package-lock.json file to do a fresh install
This doesn’t really help if the bundle engine is encapsulated inside other packages (e.g. react-script).
Maybe it’s a good idea to move release magic with breaking changes towards a new major release…
@sarazhang123 This is indeed a workaround, not real fix, as far as I am concerned. Consumers of a package shouldn’t really care about tweaking their module bundler’s config in order to make a package work… They should only do it if the package provides some additional features which require changing the config, and it’s not the case of
moment
.Just to know, where did you put these lines:
?
Will wait for a
minor
orpatch
version ofmoment
fixing this.