Why am I suddenly experiencing errors with the 'date-fns' package in my code?

This topic was automatically generated from Slack. You can find the original thread here.

Anyone else getting errors using the ‘date-fns’ package?

I have something as simple as:

import { format, addMinutes } from 'date-fns';

And I get the error of:
Error
Error: Package subpath './format/index.js' is not defined by "exports" in /tmp/__pdg__/dist/code/27385f004950730855bdb993d496a6bf0ebb39b32ed771166dacbfc79fd8d6ab/node_modules/.pnpm/date-fns-tz@2.0.0_date-fns@3.3.1/node_modules/date-fns/package.json imported from /tmp/__pdg__/dist/code/27385f004950730855bdb993d496a6bf0ebb39b32ed771166dacbfc79fd8d6ab/node_modules/.pnpm/date-fns-tz@2.0.0_date-fns@3.3.1/node_modules/date-fns-tz/esm/format/index.js

This has been working for a few months, and out of the blue it has just decided to throw this error

Successfully working as of 10 hours ago, no change, and now this

Hey , I couldn’t reproduce your issue as in the image below. Would you mind checking again?

Sure thing Just tried again, and now a similar, but different error as per attached

I am using both:
import { format, addMinutes } from ‘date-fns’;
import { utcToZonedTime } from ‘date-fns-tz’;

Example of code attached

image.png

Yeah I can see the error now.

Great, thanks for confirming Leo

Quick ChatGPT search gave this answer

Ultimately not a good position to be in lol

are you able to pin date-fns to a 2.X version? https://pipedream.com/docs/code/nodejs/#pinning-package-versions

you can try to pin the version like this:

import { format, addMinutes } from 'date-fns@2.3.0';
import { utcToZonedTime } from 'date-fns-tz@2.0.0'

The error is because the latest version of date-fns-tz is not compatible with the latest version of date-fns. You’ll need to pin them to specific versions that confirmed working together

Makes perfect sense - thanks & @UMT4G7E5P for the quick responses!

I can confirm that’s now worked

I’ll adjust my workflows accordingly

Looks like this has been known for a month now, I wonder what the hold up is for releasing a new version: Support for date-fns v3 · Issue #260 · marnusw/date-fns-tz · GitHub