I get the following error when trying to build my Svelte app:
[!] Error: 'default' is not exported by node_modules\date-fns\esm\index.js, imported by src\components\Month.svelte
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
src\components\Month.svelte (2:11)
1: <script>
2: import dateFns from 'date-fns';
I ran npm install date-fns
first, so the package exists within my project. I'm using the default rollup config that is created by using the degit template.
Any ideas on how to get this to work?
Cheers!
It's likely that date-fns
doesn't feature a default export, as stated by the error message.
Try importing the methods you need by name, for example:
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
// ]
You might also have to import specific submodules and/or locales depending on your specific requirements. The date-fns documentation is quite thorough, you should find all the answers you need there.