You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用LocalizationProvider实现本地化时触发TypeError报错崩溃求助

解决方案

问题本质

这个Cannot read properties of undefined (reading 'L')错误,核心原因是Dayjs的俄语本地化包未正确导入和注册,导致MUI的AdapterDayjs无法获取本地化所需的格式配置参数。

具体修复步骤

  1. 导入并注册Dayjs俄语本地化
    先确认已安装dayjs(未安装则执行npm install dayjs),然后在组件文件开头添加以下代码:

    import dayjs from 'dayjs';
    import 'dayjs/locale/ru'; // 引入俄语本地化文件
    import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
    import { ruRU } from '@mui/x-date-pickers/locales';
    
    // 注册俄语本地化
    dayjs.locale('ru');
    
  2. 修正LocalizationProvider配置
    将adapterLocale的字符串"ru"替换为已注册的Dayjs locale对象:

    Filter: ({ column }) => (
      <LocalizationProvider
        dateAdapter={AdapterDayjs}
        localeText={ruRU.components.MuiLocalizationProvider.defaultProps.localeText}
        adapterLocale={dayjs.locale('ru')} // 传入已注册的locale对象
      >
        <DatePicker
          onChange={(newValue) => {
            column.setFilterValue(newValue);
          }}
          renderInput={(params) => (
            <TextField
              {...params}
              helperText="Filter Mode: Less Than" // 修正拼写错误Lesss→Less Than
              sx={{ minWidth: "120px" }}
              variant="standard"
            />
          )}
          value={column.getFilterValue()}
        />
      </LocalizationProvider>
    );
    

额外建议

  • 避免同时混用@material-ui/pickers(v3)和@mui/x-date-pickers(v5),二者为新旧版本的日期选择器,易引发冲突。建议移除旧版@material-ui/pickers,统一使用新版@mui/x-date-pickers。
  • 当前@mui/x-date-pickers(5.0.18)与`@mui/material`(5.11.7)版本差异较大,建议将@mui/x-date-pickers升级至与@mui/material匹配的版本(如^5.11.7),规避潜在兼容性问题。

内容的提问来源于stack exchange,提问作者Andrei Budevich

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 02:05:44