找不到模块:' cldr'在... \ globalize \ dist \ globalize

时间:2017-11-13 19:13:36

标签: javascript node.js reactjs react-bootstrap reactstrap

在我的React应用中,我正在尝试使用react-widgets package中包含的DateTimePicker组件。我也通过reactstrap使用Bootstrap 4组件。

我已经安装了模块:

npm install --save bootstrap@4.0.0-beta reactstrap@next
npm install --save globalize react-widgets-globalize

但是当我尝试使用DateTimePicker组件时:

import Globalize from 'globalize'
import globalizeLocalizer from 'react-widgets-globalize'
import { DateTimePicker } from 'react-widgets'

class Foo extends Component {
    render() {

        Globalize.locale('en')
        globalizeLocalizer()
        let formatter = Globalize.dateFormatter({ raw: 'MMM dd, yyyy' })

        return(
            <div>
                <DateTimePicker
                    format={formatter} 
                    defaultValue={new Date()}
                    time={false}
                />
            </div>
        )
    }
}

我收到了错误

Error in ./~/globalize/dist/globalize.js
Module not found: 'cldr' in C:\Users\y\Desktop\test\node_modules\globalize\dist
 @ ./~/globalize/dist/globalize.js 22:2-25:14

Error in ./~/globalize/dist/globalize.js
Module not found: 'cldr/event' in C:\Users\y\Desktop\test\node_modules\globalize\dist

 @ ./~/globalize/dist/globalize.js 22:2-25:14

Error in ./~/globalize/dist/globalize/message.js
Module not found: 'cldr' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/message.js 22:2-26:14

Error in ./~/globalize/dist/globalize/message.js
Module not found: 'cldr/event' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/message.js 22:2-26:14

Error in ./~/globalize/dist/globalize/number.js
Module not found: 'cldr' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/number.js 22:2-27:14

Error in ./~/globalize/dist/globalize/number.js
Module not found: 'cldr/event' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/number.js 22:2-27:14

Error in ./~/globalize/dist/globalize/number.js
Module not found: 'cldr/supplemental' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/number.js 22:2-27:14

Error in ./~/globalize/dist/globalize/plural.js
Module not found: 'cldr' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/plural.js 22:2-27:14

Error in ./~/globalize/dist/globalize/plural.js
Module not found: 'cldr/event' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/plural.js 22:2-27:14

Error in ./~/globalize/dist/globalize/plural.js
Module not found: 'cldr/supplemental' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/plural.js 22:2-27:14

Error in ./~/globalize/dist/globalize/currency.js
Module not found: 'cldr' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/currency.js 18:2-24:14

Error in ./~/globalize/dist/globalize/currency.js
Module not found: 'cldr/event' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/currency.js 18:2-24:14

Error in ./~/globalize/dist/globalize/currency.js
Module not found: 'cldr/supplemental' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/currency.js 18:2-24:14

Error in ./~/globalize/dist/globalize/date.js
Module not found: 'cldr' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/date.js 22:2-28:14

Error in ./~/globalize/dist/globalize/date.js
Module not found: 'cldr/event' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/date.js 22:2-28:14

Error in ./~/globalize/dist/globalize/date.js
Module not found: 'cldr/supplemental' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/date.js 22:2-28:14

Error in ./~/globalize/dist/globalize/relative-time.js
Module not found: 'cldr' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/relative-time.js 22:2-29:14

Error in ./~/globalize/dist/globalize/relative-time.js
Module not found: 'cldr/event' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/relative-time.js 22:2-29:14

Error in ./~/globalize/dist/globalize/relative-time.js
Module not found: 'cldr/supplemental' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/relative-time.js 22:2-29:14

Error in ./~/globalize/dist/globalize/unit.js
Module not found: 'cldr' in C:\Users\y\Desktop\test\node_modules\globalize\dist\globalize

 @ ./~/globalize/dist/globalize/unit.js 22:2-27:14

我还缺少哪些npm包或配置?

2 个答案:

答案 0 :(得分:0)

尝试:npm i globalize 我在角度问题上也遇到了同样的问题,在检查了文档https://github.com/globalizejs/globalize

之后,该解决方案对我有用

答案 1 :(得分:0)

尝试删除 node-modules 文件夹并运行 npm install