date-fns: 3.0.0-alpha.2, format cannot be used as value

I installed date-fns and it installed the alpha version by default, I haven’t seen this reported before so here it is

import { format } from 'date-fns';

const createdAt = project.createdAt ? format(project.createdAt.toDate(), 'PP') : 'N/A';

Which gives me the following error 'format' cannot be used as a value because it was exported using 'export type'. The format is exported as export declare function format<DateType extends Date>(date: DateType | number | string, formatStr: string, options?: FormatOptions): string;

typescript 5.3.2 with date-fns 3.0.0-alpha.2

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Reactions: 27
  • Comments: 18 (4 by maintainers)

Most upvoted comments

Same problem on the release 3.0.0

If you change

export type * from "./index.d.ts";

to

export * from "./index.d.ts";

in index.d.mts the error goes away 🤔

Similar of course would need to be done to all entry files.

+1 waiting for fix

I shipped with the fix with date-fns@3.0.1, please try it

Yeah but you lose tree-shaking, so its only a temporary solution 😕 @FedericoBiccheddu

I shipped with the fix with date-fns@3.0.1, please try it

Thank you for the fix and your work. Very much appreciated 🙏

I shipped with the fix with date-fns@3.0.1, please try it

I updated the package and it worked fine. Thanks a lot!

https://github.com/Sailwayfun/date-fns-format.git

This is a newly set up React + Vite + Typescript project, where you can see Typescript complains about the “format” function.

Same problem with date-fns@3.0.0-rc.2 and typescript@5.3.3.

It resolves correctly if using:

import * as DateFNS from "date-fns";

DateFNS.formatISO(...)