Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date.localeData is not a function #36

Closed
1 task
moshuchao opened this issue Sep 7, 2020 · 24 comments
Closed
1 task

date.localeData is not a function #36

moshuchao opened this issue Sep 7, 2020 · 24 comments

Comments

@moshuchao
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

  • 1.按照文档,替换moment.js
  • 2.点击DatePicker

What is expected?

修复bug或者告诉我怎么样绕过去

What is actually happening?

Uncaught TypeError: date.localeData is not a function

Environment Info
antd 4.6.2
React 16.13.1
System macos
Browser chrome
@afc163 afc163 transferred this issue from ant-design/ant-design Sep 7, 2020
@iamkun
Copy link
Collaborator

iamkun commented Sep 7, 2020

请提供一个复现demo或repo

@moshuchao
Copy link
Author

我上面有CodeSandbox链接啊

@iamkun
Copy link
Collaborator

iamkun commented Sep 8, 2020

不好意思 看到链接了

@iamkun
Copy link
Collaborator

iamkun commented Sep 8, 2020

比较神奇 我CodeSandbox在线看 是有这个问题,但打包成 zip 到本地跑 就是好的

@moshuchao
Copy link
Author

在本地跑也有这个问题哈

@iamkun
Copy link
Collaborator

iamkun commented Sep 8, 2020

@moshuchao 可以提供一个 github repo 吗

@moshuchao
Copy link
Author

moshuchao commented Sep 8, 2020

我真不明白了,为什么还要GitHub repo,我本地跑的也是从codesandbox导出的压缩包,一毛一样的重现。别告诉我这个是机器人。

@urielvan
Copy link

@moshuchao 升级下 dayjs, 我升到 1.8.35 之后可以正常打开日期选择器了

@iamkun
Copy link
Collaborator

iamkun commented Sep 11, 2020

@urielvan 谢谢 我试了下 果然是这个问题, CodeSandbox 严格锁版本的, 我本地全局装的是最新版本 dayjs 已经修复这个问题了。

@tianfeng65
Copy link

我也遇到了这样的问题,升级了dayjs的版本也没有用啊

@iamkun
Copy link
Collaborator

iamkun commented Nov 24, 2020

please check if you have two dayjs node modules inside node_modules

@tianfeng65
Copy link

@iamkun
我原来的antd版本是:4.2.4,没有问题。
现在升级到了4.8.5出现这个问题。
antd-dayjs-webpack-plugin版本:1.0.1,
dayjs版本:1.9.6
我在node modules下面看到了自己装的dayjs,在rc-picker里面也有一个day.js。有点迷茫了,不知道怎么回事儿

@tianfeng65
Copy link

tianfeng65 commented Nov 24, 2020

@iamkun 我找到了你之前的解决方法,删除了package-lock.json,重新npm i 了一下,rc-picker更新了,问题解决了!感谢🙏

@fallenleavesguy
Copy link

我也是删了yarn.lock重装就好了,感觉不太好,但不知道是哪个组件依赖了他,重装那个组件就好

@BANG88
Copy link
Member

BANG88 commented Dec 2, 2021

  "resolutions": {
    "dayjs": "1.10.7"
  }

@jailsonpaca
Copy link

  "peerDependencies": {
    "dayjs": "^1.10.7",
  },

@liby
Copy link

liby commented May 11, 2022

please check if you have two dayjs node modules inside node_modules

@iamkun
I'd like to ask why this happens.

@GuichiZhao
Copy link

please check if you have two dayjs node modules inside node_modules

@iamkun I'd like to ask why this happens.

Maybe it related to how npm resolve or the order you install packages. npm can not identity two version of dayjs can be shared if you do not install them in one shot

@nanslee
Copy link

nanslee commented Jun 17, 2022

please check if you have two dayjs node modules inside node_modules

@iamkun I'd like to ask why this happens.

Maybe it related to how npm resolve or the order you install packages. npm can not identity two version of dayjs can be shared if you do not install them in one shot

In my current project, this problem will occur if the version of dayjs that rc-pick depends on is different from the version of dayjs in the project itself. Do you know the principle?

@Shuo-Mr
Copy link

Shuo-Mr commented Jul 21, 2022

Try the following code, which seems to be caused by rc-picker

import localeData from 'dayjs/plugin/localeData';
import dayjs from 'dayjs';
dayjs.extend(localeData);

@KonstantinReido
Copy link

Faced with this issue, didn't find a solution, so replaced ant-design DatePicker with a component from another package react-datepicker. Hope it's just a temporary solution.

@WeiShengv99
Copy link

I get this problem twice when i update my project, my project is pnnpm monorepo,
I don't know how to sure its OK when i update project.

@sky172839465
Copy link

sky172839465 commented Oct 18, 2022

v4.23.6 still get this problem, after some research I finally get what happen.

⚠️ Our project still using moment, and root cause is when you use locale prop in antd DatePicker, it will replace default config to rc-picker, if we don't set right config locale will be undefined and js will throw expection.

How it work

Solution

If you have set local props to DatePicker, add lang.local in local the error should be fixed.

  • origin
    const local = {
     lang: {
       placeholder: 'aaa'
     }
    }
  • fixed
    const local = {
     lang: {
       placeholder: 'aaa',
       // your datepicker lang
    ++ local: 'zh-tw'
     }
    }

Demo

demo

@Bikramghimire
Copy link

Faced with this issue, didn't find a solution, so replaced ant-design DatePicker with a component from another package react-datepicker. Hope it's just a temporary solution.

Faced with this issue, didn't find a solution, so replaced ant-design DatePicker with a component from another package react-datepicker. Hope it's just a temporary solution.

did you find any solution in this or still using react date-picker?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests