big-react-calendar:' Uncaught TypeError:无法读取属性' momentLocalizer'未定义的'

时间:2018-06-11 09:37:05

标签: node.js reactjs webpack momentjs

我正在尝试运行react-big-calendar组件的示例代码,我收到此错误: Uncaught TypeError: Cannot read property 'momentLocalizer' of undefined 这是代码:

import * as React from 'react';
import BigCalendar from 'react-big-calendar';
import moment from 'moment';

BigCalendar.momentLocalizer(moment); // or globalizeLocalizer

export class Home extends React.Component {    
  render() {
    return (
      <Row>
            <BigCalendar
              events={[]}
              startAccessor='startDate'
              endAccessor='endDate'
              defaultDate={moment().toDate()}
            />
      </Row>
    );
  }
}

有什么想法吗? 编辑:未定义的错误可能是由我在使用webpack编译打字稿时得到的错误引起的:

==== JS stack trace ==============================================

0: ExitFrame [pc: 00003FDFD9841C1]
Security context: 000002E7B1A0E589 <JSOBject>
1: resolveMappedTypeMembers(aka resolveMappedTypedMembers) [000002DAA69A7881] [C:\Users\simon\Desktop\webapp\node_modules\tpescript\lib\typecript.js:~30820])
2: resolveStructuredTypeMembers*aka resolveStructuredTypeMembers)....

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation fialed -JavaScript heap out of memory
1: node::DecodeWrite
2: node_module_register
3: v8::internal::FatalPRocessOutOfMemory
4: v8::internla::FatalProcessOutOfMemory
5: v8::internal::Heap::MaxHeapGrowingFactor
6: v8::internal::ScavengeJob::Operator=
7: v8::internal::ScavengeJob::operator=
8: v8::internal::Heap::MaxHeapGrowingFactor
9: v8::internal::Factory:::NewFillerObject
10: v8::internal::ParseInfo::GetFlag
11: 00003FDFD9841C1

1 个答案:

答案 0 :(得分:0)

在代码中使用此代码之前,您必须运行npm install react-big-calendar --save