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

Can't resolve './locale' #5472

Closed
sarazhang123 opened this issue Apr 28, 2020 · 42 comments
Closed

Can't resolve './locale' #5472

sarazhang123 opened this issue Apr 28, 2020 · 42 comments

Comments

@sarazhang123
Copy link

sarazhang123 commented Apr 28, 2020

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

image

I modified the highlight line below, webpack build successfully.

image

I think https://github.com/moment/moment/blob/develop/src/lib/locale/locales.js#L78 has some problem.

@Alanscut
Copy link
Contributor

Alanscut commented Apr 29, 2020

@sarazhang123 Can you provide a complete example on stackblitz? Please inform your operating environment This a helps a better positioning solution :).

@nerdroid23
Copy link

I also encountered this issue, it happens when I load the new version from the src directory
I am working on windows 10, with webpack:4.36.1

@MohsinGhani
Copy link

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

  • "moment": "2.24.0",
  • "moment-timezone": "^0.5.28",

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.

@sezginriggs
Copy link

Continues with 2.25.1 too.

@lykhvar
Copy link

lykhvar commented May 1, 2020

Same problem over here with 2.25.1!

@DaveCole
Copy link

DaveCole commented May 1, 2020

All I had to do was update my react project to moment 2.25.1 from 2.4.0 and moment-timezone 0.5.28 from 0.5.26 and the issue presented itself... I had updated to the react-scripts 3.4.1 from 3.3.0 and react/react-dom 16.13.1 from 16.12.0 at the same time. What's killing me is that reverting the package.json back and blowing away node_modules and reinstalling didn't fix the issue, now I'm stuck...

localebug

@lucacri
Copy link

lucacri commented May 1, 2020

Same problem for me with 2.25.1

@mhmtyasr
Copy link

mhmtyasr commented May 1, 2020

How to fix it. Nobody explains.Just waiting.

@ChristopherTrimboli
Copy link

Same issue.

@tinyfly
Copy link

tinyfly commented May 1, 2020

Downgrading to 2.24.0 fixed it for me.

@MohsinGhani
Copy link

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

  • "moment": "2.24.0",
  • "moment-timezone": "^0.5.28",

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.

Hello @sezginriggs @tinyfly @ChrisEddy @mhmtyasr @lucacri please look it.

@miguelmota
Copy link

Downgrading to the previous minor version (2.24.0) works as usual:

npm install --save --save-exact moment@2.24.0

@agrohs
Copy link

agrohs commented May 1, 2020

Related to: #5489 (which somehow seems to have been closed)

@agrohs
Copy link

agrohs commented May 1, 2020

How can we make sure this works with moment-timezone???

@agrohs
Copy link

agrohs commented May 1, 2020

zburke added a commit to folio-org/ui-inventory that referenced this issue May 1, 2020
Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0`:
* [5489](moment/moment#5489)
* [5472](moment/moment#5472)
@fransPR
Copy link

fransPR commented May 2, 2020

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

* "moment": "2.24.0",

* "moment-timezone": "^0.5.28",

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.

Yes, the problem is the version, Thank for your answer.

@rhuffy
Copy link

rhuffy commented May 2, 2020

I am seeing a similar issue when trying to build my react project on Github Actions CI. No warnings were emitted when building locally. Downgrading to 2.24.0 solved the issue.

@linxiaowu66
Copy link

same issue with 2.25.1

@zgw946
Copy link

zgw946 commented May 2, 2020

大家好!
最近几个小时我都遇到了同样的问题,最后我通过更改时间版本解决了它。

原因:
在17小时前将新版本从2.24.0发行到2.25.0

解决方案:
步骤1:更改版本

  • “ moment”:“ 2.24.0”,
  • “ moment-timezone”:“ ^ 0.5.28”,

步骤2:如果您使用的是yarn,请在package.json文件中添加分辨率,例如
“ dependencies” {
“ moment”:“ 2.24.0”,
“ moment-timezone”:“ ^ 0.5.28”
},
“ resolutions” :{
“ moment”:“ 2.24.0”
},

谢谢。
不行啊

@m2mathew
Copy link

m2mathew commented May 2, 2020

2.25.1 presents the "locale" issue, as others have stated. When I use exactly 2.24.0 it works correctly.

@B2D1
Copy link

B2D1 commented May 2, 2020

same problem happened in v2.25.1,then I try to add

"dependencies" {
  "moment": "2.24.0",
},
"resolutions": {
  "moment": "2.24.0"
},

@rrrix
Copy link

rrrix commented May 2, 2020

I went with this bandaid:

  "dependencies: {
      "moment": "^2 <2.25 || ^2 >2.25",
  }

This avoids forever version pinning to moment@2.24.0 until the end of time, with the assumption (hope?) that this gets fixed by the time moment@2.26.0 rolls out, and if not then it'll remind me to check this thread :) tip: try semver.npmjs.com!

@zgw946
Copy link

zgw946 commented May 2, 2020 via email

@scottgale
Copy link

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?

@tonix-tuft
Copy link

tonix-tuft commented May 2, 2020

I can confirm what others have stated, 2.25.1 breaks with Can't resolve './locale' warning. Downgrading to 2.24.0 works, but binds projects to a specific version of moment...

Waiting for a fix.

@NathanChannon
Copy link

NathanChannon commented May 3, 2020

@chandra-devs beat me to it ^^

I also have an open ticket for this. If you're able to use Yarn, then using package.json "resolutions" is your way out.

If you're using npm, then you can use this npm-force-resolutions to accomplish the same result, but beware you must reference momentjs in the dependencies if you weren't already.

zburke added a commit to folio-org/ui-users that referenced this issue May 4, 2020
Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0`
([5489](moment/moment#5489), [5472](moment/moment#5472)).

The `resolutions` entry is necessary because `2.25` leaks in via
transitive deps. I don't know why it is necessary here when it isn't,
say, in ui-circulation, which pulls it in via the same route of
stripes-cli and stripes-core. That makes no sense. Alas.

Refs [STRIPES-678](https://issues.folio.org/browse/STRIPES-678)
bluewings pushed a commit to bluewings/react-genie-form that referenced this issue May 4, 2020
@guifeliper
Copy link

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

  • "moment": "2.24.0",
  • "moment-timezone": "^0.5.28",

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.

What solved for me was:

  1. rm -rf node_modules
  2. change manually the package.json with the quote comment. (dependencies and resolutions)
  3. yarn install.

@ichernev
Copy link
Contributor

ichernev commented May 4, 2020

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.

@ichernev ichernev closed this as completed May 4, 2020
@cjmaynar
Copy link

cjmaynar commented May 4, 2020

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:

image

I'm using

"moment": "^2.25.2",
"moment-timezone": "^0.5.28",

I've deleted my node_modules and package-lock.json file to do a fresh install

zburke added a commit to folio-org/ui-users that referenced this issue May 4, 2020
Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0`
([5489](moment/moment#5489), [5472](moment/moment#5472)).

The `resolutions` entry is necessary because `2.25` leaks in via
transitive deps. 

Refs [STRIPES-678](https://issues.folio.org/browse/STRIPES-678)
zburke added a commit to folio-org/ui-checkout that referenced this issue May 5, 2020
Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0`
([5489](moment/moment#5489), [5472](moment/moment#5472)).

The `resolutions` entry is necessary because `2.25` leaks in via
transitive deps.

Refs [STRIPES-678](https://issues.folio.org/browse/STRIPES-678)
zburke added a commit to folio-org/ui-circulation that referenced this issue May 7, 2020
`moment` `v2.25` less than `v2.25.3` caused many webpack-related bugs
([5489](moment/moment#5489), [5472](moment/moment#5472)).

Refs STRIPES-678
zburke added a commit to folio-org/ui-circulation that referenced this issue May 7, 2020
`moment` `v2.25` less than `v2.25.3` caused many webpack-related bugs
([5489](moment/moment#5489), [5472](moment/moment#5472)).

Refs STRIPES-678
zburke added a commit to folio-org/ui-calendar that referenced this issue May 7, 2020
Pin `moment` at `~2.24.0` in light of multiple issues with `2.25.0`
([5489](moment/moment#5489), [5472](moment/moment#5472)).

Refs [STRIPES-678](https://issues.folio.org/browse/STRIPES-678)
@abramovks
Copy link

import like this solved for me

"moment": "^2.29.4"

import * as moment from 'moment'
import 'moment/locale/ru'
moment.locale('ru')

@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

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