I am getting following error: Module \'\".../node_modules/moment/moment\"\' has no exported member \'default\'
when I use
import * as _moment from
That's because moment
does not have something called default
did you mean defaultFormat
?
Also you don't need your second import. You can just say _moment.defaultFormat
I had so much trouble with trying to properly import Moment that I switched to the date-fns library instead.
date-fns takes a somewhat different approach - as the name implies, it's a collection of date functions, rather than a huge 'god object' that does everything.
The additional benefits are that a) you can import just the individual functions that you need, and b) if you import the whole thing, it tree-shakes really well. So you wind up with a much smaller impact on your module size.
From Moment's Docs:
Note: If you have trouble importing moment, try adding "allowSyntheticDefaultImports": true in compilerOptions in your tsconfig.json file and then use the syntax