DateRange-Picker中断应用程序

时间:2019-11-07 09:25:23

标签: javascript reactjs typescript

我试图在我的react应用程序上实现一个日期范围选择器,并且尝试使用(https://github.com/onefinestay/react-daterange-picker)中的日期选择器。

因此,我只是从github页面(npm install react-daterange-picker and after npm install --save @types/react-daterange-picker)进行了初始安装,而在初始npm install之后,我用npm WARN react-daterange-picker@2.0.1 requires a peer of moment-range@^3.0.3 but none is installed. You must install peer dependencies yourself.发出了警告。 尽管我已经在该项目中获得了矩距的最新版本

然后我只是从github复制了代码并启动了npm,它给了我一个空白页,并显示了以下错误和警告

错误(从控制台)

 Uncaught TypeError: Object(...) is not a function at 
 Module../node_modules/react-daterange-picker/src/moment-range.js 
 (bundle.js:103437) at __webpack_require__ (bundle.js:727) at fn 
 (bundle.js:101) at Object../node_modules/react-daterange- 
 picker/dist/moment-range.js (bundle.js:102813) at __webpack_require__ 
 (bundle.js:727) at fn (bundle.js:101) at Object../node_modules/react- 
 daterange-picker/dist/DateRangePicker.js (bundle.js:101077) at 
 __webpack_require__ (bundle.js:727) at fn (bundle.js:101) at Module. 
 <anonymous> (bundle.js:4063)

警告(从终端)

 WARNING in ./node_modules/react-daterange-picker/src/moment-range.js 
 3:15-27 "export 'extendMoment' was not found in 'moment-range' @ 
 ./node_modules/react-daterange-picker/dist/moment-range.js @ 
 ./node_modules/react-daterange-picker/dist/utils/getYearMonth.js @ 
 ./node_modules/react-daterange-picker/dist/DateRangePicker.js

代码

import React, {Component} from 'react'
import DateRangePicker from 'react-daterange-picker'
import 'react-daterange-picker/dist/css/react-calendar.css' // For some basic styling. (OPTIONAL)

interface IMyExampleState {
    dates: any
}

export default class MyExample extends Component<{}, IMyExampleState> {
    constructor(props) {
        super(props)

        this.state = {
            dates: null
        }
    }

    onSelect = dates => this.setState({ dates })

    render() {
        return (
            <div>
                <DateRangePicker
                    onSelect={this.onSelect}
                    value={this.state.dates}
                />
            </div>
        )
    }
}



旁注: 我使用的是webpack@4.40.2而不是create-react-app

0 个答案:

没有答案