ant-design: TypeError: (0 , _moment2.default) is not a function
I’m trying to use antd as a component library with my existing build system (webpack 2). Can I use components from this library without importing the entire build system? I did
npm install antd
and in my page, added
import { DatePicker } from 'antd'
export function Page(){
return <DatePicker/>
}
Error
Uncaught TypeError: (0 , _moment2.default) is not a function
at Function.getDefaultProps (?d41d*:78)
at Object.createClass (ReactClass.js:675)
at Object../node_modules/rc-time-picker/lib/Panel.js (?d41d*:45)
at __webpack_require__ (bootstrap d2f4533…:689)
at fn (bootstrap d2f4533…:110)
at Object../node_modules/antd/lib/date-picker/wrapPicker.js (wrapPicker.js:21)
at __webpack_require__ (bootstrap d2f4533…:689)
at fn (bootstrap d2f4533…:110)
at Object../node_modules/antd/lib/date-picker/index.js (index.js:23)
at __webpack_require__ (bootstrap d2f4533…:689)
Environment
webpack 2 Antd 2.4.3 Node 7 OSX 10.10
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 25 (9 by maintainers)
Commits related to this issue
- Fix moment locale error when importing antd ref ant-design/ant-design#3947 & ant-design/ant-design#4491 — committed to afc163/react-boilerplate by afc163 7 years ago
- Fix moment locale error when importing antd ref ant-design/ant-design#3947 & ant-design/ant-design#4491 — committed to afc163/react-boilerplate by afc163 7 years ago
- Fix moment locale error when importing antd working with webpack2 ref ant-design/ant-design#3947 & ant-design/ant-design#4491 — committed to afc163/react-boilerplate by afc163 7 years ago
Try this: https://github.com/webpack/webpack/issues/1694#issuecomment-164481066
@KhushbooTaneja This alias has to be added in the
webpack
configuration. details.The only way i could work around this was by adding an alias
But by adding this the bundle size is bloated since it includes many other language locales.
I’m having this exact same issue. I don’t think it’s related to babel, but I do believe it’s a problem with moment lib. It seems to me that moment is not webpack friendly, as I already had some issues with it in the past and it keeps occurring.
Probably related:
@18601673727
Found a workaround for using antd in react-boilerplate: https://github.com/ant-design/ant-design/issues/4491#issuecomment-270887624
Ok now when I try to change locale like this:
import enUS from 'antd/lib/locale-provider/en_US';
I get the following error:
In my case, I managed to to get it working by installing moment with specific version: “moment”: “2.15.2”. Later version of moment seems to cause the above problem for me.
@MateusDantas this is exactly why we recently switched to date-fns