Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: format is not a function in date-fns

I am migrating from moment to date-fns and following docs on the official site.

I have installed date-fns from npm and when I try to use I get this error:

TypeError: format is not a function

I have tried import, require but they all give same error.

var format = require('date-fns/format')
import format from 'date-fns/format'

Also the typeof(format) returns undefined.

Using v1.29.0 on Nodejs

like image 847
Rohit Kumar Avatar asked May 11 '26 03:05

Rohit Kumar


1 Answers

From the doc.

import { format } from 'date-fns';
like image 133
Faheem Avatar answered May 13 '26 16:05

Faheem