找不到模块:无法解析“E:\\frontend\\node_modules\\@mui\\styled-engine”中的“@emotion/react”

新手上路,请多包涵

我正在尝试从 @mui/material/Box 导入一个盒子组件。我使用以下命令安装了 MUI 5 npm i @mui/material 。但是这个错误正在发生, Module not found: Can't resolve '@emotion/react' in 'E:\frontend\node_modules\@mui\styled-engine'

这是我的代码。

 import * as React from 'react';
import Box from '@mui/material/Box';

export default function WhiteSpace() {
  return (
    <div style={{ width: 200 }}>
      <Box
        component="div"
        sx={{
          whiteSpace: 'nowrap',
          my: 2,
          bgcolor: 'background.paper',
        }}
      >
        White Space Nowrap. White Space Nowrap.
      </Box>
      <Box
        component="div"
        sx={{
          whiteSpace: 'normal',
          my: 2,
          bgcolor: 'background.paper',
        }}
      >
        White Space Normal. White Space Normal.
      </Box>
    </div>
  );
}

有人可以帮我解决这个问题吗?

原文由 stmp_lee 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 407
2 个回答

@emotion/react and @emotion/styled are peer dependencies of many mui packages, ie @mui/material .这使我们可以更自由地选择要使用的情感版本,但这确实意味着我们必须自己安装依赖项。

 npm i @emotion/react @emotion/styled

原文由 chantey 发布,翻译遵循 CC BY-SA 4.0 许可协议

利用

npm i @emotion/react @emotion/styled

安装 @emotion/react 然后它会解决你的问题

原文由 Limon 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题