React-big-calendar: Uncaught TypeError: moment is not a function

Created on 2 May 2017  路  4Comments  路  Source: jquense/react-big-calendar

I follow the tutorial from http://intljusticemission.github.io/react-big-calendar/examples/index.html

so I write a sample, but when I run ,

it shows the message below :

Uncaught TypeError: moment is not a function
at DateLocalizer.format (moment.js:22)
at _format (localizer.js:21)
at DateLocalizer.format (localizer.js:47)
at DateLocalizer.format (moment.js:22)
at _format (localizer.js:21)
at DateLocalizer.format (localizer.js:47)
at Object.format (localizer.js:84)
at viewLabel (viewLabel.js:35)
at Calendar.render (Calendar.js:172)
at ReactCompositeComponent.js:796

can anyone tell my what's going on? thx

my snippet code

BigCalendar.setLocalizer(
  BigCalendar.momentLocalizer(moment)
);

const MyCalendar = props => (
  <div>
    <BigCalendar
      events={events}
      startAccessor='startDate'
      endAccessor='endDate'
    />
  </div>
);

Most helpful comment

You have to install moment, e.g. npm install --save moment, and then import it like this:
import moment from 'moment'.

All 4 comments

you need to import moment or otherwise make it available

I already import node_module/lib/localizers/moment

if I add 'culture' props the message become " m.locale is not a function "

You have to install moment, e.g. npm install --save moment, and then import it like this:
import moment from 'moment'.

In typescript
import moment from 'moment'
TS1192: Module '"/node_modules/moment/moment"' has no default export.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gsavvid picture gsavvid  路  3Comments

npalansky picture npalansky  路  3Comments

manutenfruits picture manutenfruits  路  3Comments

kweisamx picture kweisamx  路  4Comments

The-Oracle picture The-Oracle  路  3Comments