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

Vite项目中访问MUI组件时React Router报'duration'未定义错误求助

解决MUI组件Cannot read properties of undefined (reading 'duration')报错

常见原因及解决方案:

  • 未配置ThemeProvider
    MUI组件依赖主题上下文提供样式配置,未在外层包裹ThemeProvider会导致找不到duration这类主题属性。在应用根组件外层添加ThemeProvider:

    import { ThemeProvider, createTheme } from '@mui/material/styles';
    import CssBaseline from '@mui/material/CssBaseline';
    
    const theme = createTheme();
    
    function App() {
      return (
        <ThemeProvider theme={theme}>
          <CssBaseline />
          {/* 你的路由、Drawer、AppBar等组件 */}
        </ThemeProvider>
      );
    }
    
    export default App;
    
  • 组件导入路径错误
    确保从@mui/material正确导入组件,避免使用旧包或错误路径:

    import Drawer from '@mui/material/Drawer';
    import AppBar from '@mui/material/AppBar';
    
  • 依赖缓存或版本问题
    尝试清理依赖并重新安装,同时清除Vite缓存:

    rm -rf node_modules package-lock.json
    npm install
    npm run dev -- --force
    
  • 自定义主题缺失transition配置
    若使用了自定义主题,确认transitions.duration配置存在,示例:

    const theme = createTheme({
      transitions: {
        duration: {
          shortest: 150,
          shorter: 200,
          standard: 300,
          // 其他必要的duration配置项
        },
      },
    });
    

内容的提问来源于stack exchange,提问作者Alb Rick Bi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 13:23:16