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

Upgrade from date-fns 2.30 to 3.0.6: Cannot find module 'date-fns/format/index.js' from 'node_modules/date-fns-tz/format/index.js' #266

Closed
ningji opened this issue Jan 3, 2024 · 5 comments · Fixed by #273

Comments

@ningji
Copy link

ningji commented Jan 3, 2024

was on
date-fns:2.30.0
date-fns-tz:2.0.0

When upgraded to date-fns: 3.0.6 from 2.30.0 (date-fns-tz stays on v2.0.0 as this is their latest), i got this:

Cannot find module 'date-fns/format/index.js' from 'node_modules/date-fns-tz/format/index.js'

Require stack:
  node_modules/date-fns-tz/format/index.js
  node_modules/date-fns-tz/index.js

Any suggestions other than stay on the old version pls ?

@Deanmv
Copy link

Deanmv commented Jan 3, 2024

Duplicate of #260

@philios33
Copy link

Somebody has tried to fix it here:
#262

and there is a PR to upgrade to v3 of date-fns which will probably be released soon. But yeah, ultimately this package is now broken since 18th Dec when v3 came out.

Your options are:

  1. Downgrade
  2. Fix it
  3. Wait

@jeslenbucci
Copy link

But yeah, ultimately this package is now broken since 18th Dec when v3 came out.

The package isn't broken. It's just not compatible with v3. The first sentence of the repo clearly states in the readme (which hasn't been updated since last year): 'Time zone support for date-fns v2.0.0'. The package continues to function properly with the version of date-fns is was built for.

@philios33
Copy link

The problem is that npm reads dependencies from the package.json file, not from the README. Try to install this package in a fresh project and you will see it installs date-fns v3 instead of v2 because it thinks it supports it. There are already 2 PRs for this. 1 has been approved, but v2.0.0 is still the latest published version on npm. Not sure on the timelines

@TakashiAihara
Copy link

To work around dependency issues, here's how you can adjust your package.json:

For npm

Fix the version of date-fns in your dependencies to the latest minor version of v2.

{
  ...
  "overrides": {
    "date-fns": "2.x"
  }
}

For yarn

Install date-fns directly as Yarn requires this dependency resolution.

{
  ...
  "dependencies": {
    "date-fns": "2.x"
  }
}

For pnpm

Conform to pnpm's method by fixing the date-fns in your dependencies to v2.

{
  ...
  "pnpm": {
    "overrides": {
      "date-fns": "2.x"
    }
  }
}

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.

5 participants