marnusw/date-fns-tz

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'

Closed this issue · 5 comments

ningji commented

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 commented

Duplicate of #260

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

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.

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

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"
    }
  }
}