Importing moment into Angular gives error

前端 未结 3 1847
独厮守ぢ
独厮守ぢ 2021-01-13 09:12

I am getting following error: Module \'\".../node_modules/moment/moment\"\' has no exported member \'default\'when I use

import * as _moment from

3条回答
  •  逝去的感伤
    2021-01-13 09:59

    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.

提交回复
热议问题