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' #837

Open
ajayar opened this issue May 1, 2020 · 19 comments
Open

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

ajayar opened this issue May 1, 2020 · 19 comments

Comments

@ajayar
Copy link

ajayar commented May 1, 2020

After auto-updating to moment 2.25, am getting this error

prototype.js:1 Uncaught Error: Cannot find module './locale'
at prototype.js:1
at Module. (prototype.js:1)
at f ((index):1)
at moment-timezone.js:11
at Object. (moment-timezone.js:6)
at f ((index):1)
at Object. (index.js:1)
at f ((index):1)
at Module.1033 (network.js:27)
at f ((index):1)

@BrianSHenderson
Copy link

Same issue here

@RobUnderscore
Copy link

Same. Supposedly fixed by reverting moment to 2.24.0 -

moment/moment#4216

That didn't fix it for me.

@dylanjt
Copy link

dylanjt commented May 1, 2020

Same issue here. This is currently breaking when built for our dev environment. Running locally appears to work fine. Using CRA-based app.

EDIT: I had installed moment-timezone, and was importing moment implicitly. I have attempted to explicitly install the 2.24.0 version, but that does not work.

EDIT: since this appears to be a pertinent point, I should note that our breakage is also occurring when deployed via CircleCI.

@jontybrook
Copy link

I'm having the same issue. Locking to 2.24 doesn't fix it for me either. Intriguingly i'm seeing this when our CI makes production builds, but not in local dev builds.

@RobUnderscore
Copy link

RobUnderscore commented May 1, 2020

I'm having the same issue. Locking to 2.24 doesn't fix it for me either. Intriguingly i'm seeing this when our CI makes production builds, but not in local dev builds.

Same. In order to test locally I'm having to perform a production build locally and use serve or http-server to start it up.

Also using CRA.

@mike-ruane
Copy link

here's moment & moment-timezone in my package.json:

"moment": "^2.22.2",
"moment-timezone": "^0.5.23",

It's a react typescript app, with corresponding types for moment-timezone "@types/moment-timezone": "^0.5.9". yarn install now returns import errors on moment. I've bumped moment version down to 2.22.1, which solved this issue, but then introduced the locale issue mentioned above. I get the following error in react-scripts-ts build:

./node_modules/moment-timezone/node_modules/moment/src/lib/locale/locales.js
78:12-82:13 Critical dependency: the request of a dependency is an expression

This is since yesterday, as this build ran successfully on master branch CI then.

@spacejamtda
Copy link

spacejamtda commented May 1, 2020

I previously only had moment-timezone as a dependency but the following worked for me after adding the following to package.json

"dependencies": {
    "moment": "2.24.0",
    "moment-timezone": "0.5.28"
},
"resolutions": {
    "moment": "2.24.0"
}

@dylanjt
Copy link

dylanjt commented May 1, 2020

@spacejamtda thank you, this got our dev env back online.

@jontybrook
Copy link

In my case I was finally able to resolve this by adding

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

to package.json, and also modifying yarn.lock. I'm using a lerna monorepo and yarn workspaces, so I had to add this to the root package.json so that the resolution prevented yarn from installing 2.25.0 where ^ is used.

Sincerely hope this issue is fixed in moment soon!

@ajayar
Copy link
Author

ajayar commented May 1, 2020

@spacejamtda thx. Your solution fixed it for the time being. I'm using CRA, the local builds work fine but the production ones fail.

@kkerley
Copy link

kkerley commented May 1, 2020

I was having this problem suddenly and the way I ultimately fixed it for both local dev and remote prod was to implement @spacejamtda's suggestion (I don't use moment-timezone, though). My package.json did not have the "resolutions" part. I also deleted my package-lock.json file and node_modules directory, reinstalled, and then everything worked.

@agrohs
Copy link

agrohs commented May 1, 2020

I tried the resolution above from @spacejamtda but no luck...we are desperate after fighting this issue all day since 2.25 was released

@DaveCole
Copy link

DaveCole commented May 1, 2020

The rollback on #5472 from @miguelmota did it for me:

npm install --save --save-exact [email protected]

That's the last time I do a package update on a Friday afternoon before a launch :)

@vitaliyhayda
Copy link

same issue

@nikunjkonduru
Copy link

I think the @spacejamtda resolutions solution probably works for for people using yarn. I am not sure npm supports resolutions out of the box. I read about npm-force-resolutions, but having problem implementing it.

@vitaliyhayda
Copy link

vitaliyhayda commented May 3, 2020

Until moment fixes the issue - feel free to use my fork with a locked moment version:

npm install --save vitaliyhayda/moment-timezone

@agrohs
Copy link

agrohs commented May 4, 2020

I tried the resolution above from @spacejamtda but no luck...we are desperate after fighting this issue all day since 2.25 was released

Quick update that this was related to monorepo/yarn workspaces and it just requires the resolutions to be placed in the root level package.json:

  "resolutions": {
    "**/moment": "2.24.0"
  }

@drummy2
Copy link

drummy2 commented May 20, 2020

Adding the resolutions in your package is only a plaster on a bleeding wound. When is there going to be a final fix?

@ichernev
Copy link
Contributor

I'm a bit confused here, what exactly is the issue with moment and how should we fix it? Would peerDependency work?

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

No branches or pull requests