Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2: How to fix usage of moment.js errors

Since updating to RC.0, I'm getting the following build error to do with moment.js (which I have installed via npm):

[13:44:16]  Error: Cannot call a namespace ('moment')

I have tried referencing moment in two ways:

  • import * as moment from 'moment';
  • import moment from 'moment'

The error is the same.

Q) What am I doing wrong? This was working before RC.0

like image 422
Dave Avatar asked Oct 04 '16 12:10

Dave


People also ask

Is moment JS still used?

The people behind Moment. js are even advising against using it. We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done.

How do I get the current time in Momentjs?

var CurrentDate = moment(). format();

Why do we use moment JS?

js is a JavaScript package that makes it simple to parse, validate, manipulate, and display date/time in JavaScript. Moment. js allows you to display dates in a human-readable format based on your location.

Is moment JS open source?

Moment. js is a free and open source JavaScript library that removes the need to use the native JavaScript Date object directly.


1 Answers

With import * as Moment from 'moment'; I was getting the error: Cannot call a namespace ('Moment').

Changing it to import Moment from 'moment'; resolved the issue.

like image 63
Ian Pinto Avatar answered Sep 19 '22 09:09

Ian Pinto