I managed to run it successfully by using require as shown below:

const fns = require('date-fns')

console.log(fns.format(new Date(), "'Today is a' eeee"))

Update:

I installed node v16.6.1 following the instructions in this answer and now I can run the following code successfully:

import { format } from 'date-fns';

console.log(format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSS"));
Answer from Arvind Kumar Avinash on Stack Overflow
🌐
npm
npmjs.com › package › date-fns
date-fns - npm
import { compareAsc, format } from "date-fns"; format(new Date(2014, 1, 11), "yyyy-MM-dd"); //=> '2014-02-11' const dates = [ new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10), ]; dates.sort(compareAsc); //=> [ // Wed Feb 11 1987 00:00:00, // Mon Jul 10 1989 00:00:00, // Sun Jul 02 1995 00:00:00 // ] The library is available as an npm package.
      » npm install date-fns
    
Published   Sep 17, 2024
Version   4.1.0
🌐
date-fns
date-fns.org
date-fns - modern JavaScript date utility library
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
🌐
GitHub
github.com › date-fns › date-fns
GitHub - date-fns/date-fns: ⏳ Modern JavaScript date utility library ⌛️
import { compareAsc, format } from "date-fns"; format(new Date(2014, 1, 11), "yyyy-MM-dd"); //=> '2014-02-11' const dates = [ new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10), ]; dates.sort(compareAsc); //=> [ // Wed Feb 11 1987 00:00:00, // Mon Jul 10 1989 00:00:00, // Sun Jul 02 1995 00:00:00 // ] The library is available as an npm package.
Author   date-fns
🌐
npm
npmjs.com › package › date-fns-tz
date-fns-tz - npm
Time zone support for date-fns v3 with the Intl API. Latest version: 3.2.0, last published: a year ago. Start using date-fns-tz in your project by running `npm i date-fns-tz`. There are 1941 other projects in the npm registry using date-fns-tz.
      » npm install date-fns-tz
    
Published   Sep 30, 2024
Version   3.2.0
Author   Marnus Weststrate
🌐
npm
npmjs.com › package › date-fns-jalali
date-fns-jalali - npm
import { compareAsc, format, newDate } from "date-fns-jalali"; format(new Date(2014, 1, 11), "yyyy-MM-dd"); //=> '1392-11-22' newDate(1392, 10, 22); // => Tue Feb 11 2014 00:00:00 format(newDate(1392, 10, 22), "yyyy MMMM d"); // 1392 بهمن 22 const dates = [ new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10), ]; dates.sort(compareAsc); //=> [ // Wed Feb 11 1987 00:00:00, // Mon Jul 10 1989 00:00:00, // Sun Jul 02 1995 00:00:00 // ] The library is available as an npm package.
      » npm install date-fns-jalali
    
🌐
IronPDF
ironpdf.com › ironpdf for node.js › ironpdf for node.js blog › node help › date-fns npm
date-fns NPM (How It Works For Developers)
June 23, 2025 - date-fns uses existing native dates data types, it doesn’t extend core objects for safety’s sake, meaning it will avoid modifying or adding functionalities to those built in date data types
🌐
Best of JS
bestofjs.org › projects › date-fns
Best of JS • date-fns
import { compareAsc, format } from "date-fns"; format(new Date(2014, 1, 11), "yyyy-MM-dd"); //=> '2014-02-11' const dates = [ new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10), ]; dates.sort(compareAsc); //=> [ // Wed Feb 11 1987 00:00:00, // Mon Jul 10 1989 00:00:00, // Sun Jul 02 1995 00:00:00 // ] The library is available as an npm package.
Find elsewhere
🌐
GitHub
github.com › date-fns › date-fns › issues › 980
Error: Can't resolve 'date-fns/format' · Issue #980 · date-fns/date-fns
November 8, 2018 - Why am I getting: Module not found: Error: Can't resolve 'date-fns/format' after installing date-fns like this: npm install date-fns --save I am requiring it like this: const format = require('date-fns/format'); I can see this in my pack...
Published   Nov 08, 2018
🌐
Libraries.io
libraries.io › npm › date-fns
date-fns 4.1.0 on npm - Libraries.io - security & maintenance data for open source software
import { compareAsc, format } from "date-fns"; format(new Date(2014, 1, 11), "yyyy-MM-dd"); //=> '2014-02-11' const dates = [ new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10), ]; dates.sort(compareAsc); //=> [ // Wed Feb 11 1987 00:00:00, // Mon Jul 10 1989 00:00:00, // Sun Jul 02 1995 00:00:00 // ] The library is available as an npm package.
🌐
npm
npmjs.com › package › @date-io › date-fns
@date-io/date-fns - npm
Latest version: 3.2.1, last published: a year ago. Start using @date-io/date-fns in your project by running `npm i @date-io/date-fns`. There are 969 other projects in the npm registry using @date-io/date-fns.
      » npm install @date-io/date-fns
    
Published   Mar 07, 2025
Version   3.2.1
Author   Dmitriy Kovalenko
🌐
Yarn
classic.yarnpkg.com › en › package › date-fns
date-fns
Fast, reliable, and secure dependency management.
🌐
npm
npmjs.com › package › ngx-date-fns
ngx-date-fns - npm
A collection of utilities built around date-fns functions. This pipe is (impure), but there's the pure version dfnsFormatRelativeToNowPure too. Same as dfnsFormatRelative but the date to comapre against is always Date.now(). ... Given a weekday number, returns its name. Optional weekday format.
      » npm install ngx-date-fns
    
Published   May 14, 2025
Version   12.0.1
🌐
Socket
socket.dev › npm › package › date-fns
date-fns - npm Package Security Analysis - Socket
It offers a rich set of features for parsing, formatting, manipulating, and querying dates. It's built on the Intl API and provides time zone support out of the box, which is more comprehensive than date-fns's approach to time zones. ... The npm package date-fns receives a total of 42,780,022 ...
🌐
Snyk
snyk.io › advisor › date-fns › date-fns code examples
Top 5 date-fns Code Examples | Snyk
export const ScopeDays = (props: ScopeDaysProps) => { const { tasks, date } = props; const days = groupBy(tasks, t => formatDate(parseDate(t.date.split(' ')[0]))); const start = startOfMonth(date); let end = endOfMonth(date); const now = new Date(); if (end > now) { end = now; } if (end > start) { // Ensure that days before the current day are given a scope, even with no tasks eachDayOfInterval({ start, end }).forEach(day => { const key = formatDate(day); if (!days[key]) days[key] = []; }); }
🌐
GitHub
github.com › date-fns › date-fns › blob › main › docs › gettingStarted.md
date-fns/docs/gettingStarted.md at main · date-fns/date-fns
import { format, compareAsc } from "date-fns"; format(new Date(2014, 1, 11), "MM/dd/yyyy"); //=> '02/11/2014' const dates = [ new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10), ]; dates.sort(compareAsc); //=> [ // Wed Feb 11 1987 00:00:00, // Mon Jul 10 1989 00:00:00, // Sun Jul 02 1995 00:00:00 // ] date-fns includes some optional features as submodules in the npm package.
Author   date-fns
🌐
DevDocs
devdocs.io › date_fns
DevDocs — date-fns documentation
date-fns 2.29.2 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
🌐
Runkit
npm.runkit.com › date-fns
RunKit + npm: date-fns
This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including date-fns with all npm packages installed.
🌐
GitHub
github.com › date-fns › babel-plugin-date-fns
GitHub - date-fns/babel-plugin-date-fns
$ npm i --save date-fns $ npm i --save-dev babel-plugin-date-fns ... import differenceInYears from 'date-fns/differenceInYears'; import format from "date-fns/format"; import formatDistance from "date-fns/formatDistance";
Starred by 92 users
Forked by 15 users
Languages   JavaScript
🌐
Npm
npm.io › package › date-fns
Date-fns NPM | npm.io
import { compareAsc, format } from "date-fns"; format(new Date(2014, 1, 11), "yyyy-MM-dd"); //=> '2014-02-11' const dates = [ new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10), ]; dates.sort(compareAsc); //=> [ // Wed Feb 11 1987 00:00:00, // Mon Jul 10 1989 00:00:00, // Sun Jul 02 1995 00:00:00 // ] The library is available as an npm package.