Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing moment into Angular gives error

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

import * as _moment from 'moment'; import { default as _rollupMoment } from 'moment'; const moment = _rollupMoment || _moment;

like image 756
CodeHip Avatar asked Mar 15 '18 13:03

CodeHip


People also ask

Can I use moment JS in angular?

You can now use Moment. js in your Angular app, as long as you import it into the component in which you plan to use it.

What is Moment () in angular?

Moment. js is used for parsing, validating, manipulating, and displaying dates and times in JavaScript. In this guide, we are adding Moment. js to Angular (application platform).


2 Answers

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

like image 88
Daniel Chikaka Avatar answered Sep 19 '22 10:09

Daniel Chikaka


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

like image 34
ochs.tobi Avatar answered Sep 22 '22 10:09

ochs.tobi