找不到模块:无法解析“@mui/material/utils”:(v5,其中包括名称更改。)

Han*_*Han 50 reactjs material-ui

当我尝试从 Material UI 导入一些图标时,我可以看到此错误。我按照建议安装了一些模块,但仍然没有修复。

包.json

    "@material-ui/core": "^4.12.3",
    "@mui/icons-material": "^5.0.1",
    "@mui/lab": "^5.0.0-alpha.49",
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下命令安装 /utils,

$ npm install @mui/material/utils
Run Code Online (Sandbox Code Playgroud)

错误:

npm ERR! code ENOLOCAL
npm ERR! Could not install from "@mui\material\utils" as it does not 
contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Han\AppData\Roaming\npm-cache\_logs\2021-10-03T21_47_03_649Z-debug.log
Run Code Online (Sandbox Code Playgroud)

有什么我错过的吗?

**经过一番研究,我删除了“@material-ui/core”并安装了“@mui/core”。我认为出现此错误是因为名称从material更改为mui?

    "@mui/core": "^5.0.0-alpha.49",
    "@mui/icons-material": "^5.0.1",
    "@mui/lab": "^5.0.0-alpha.49",
    "@mui/utils": "^5.0.1",
Run Code Online (Sandbox Code Playgroud)

谢谢。

小智 63

试试这个命令 npm install @mui/material @emotion/react @emotion/styled

请参阅React mui 的安装说明。

  • 已投票,但也请尝试在您的答案中包含解释:) (12认同)
  • 是的,除非你先解释一下自己,否则请不要给出有用的答案 (2认同)

Gas*_*ass 31

为什么会发生这种情况?

在安装MUI 组件库之前安装MUI 图标包 时会发生此错误。MUI 图标包需要包才能正常工作。@mui/material @emotion/react @emotion/styled

解决方案

运行以下行之一

// with npm
npm install @mui/material @emotion/react @emotion/styled

// or if you prefer yarn
yarn add @mui/material @emotion/react @emotion/styled
Run Code Online (Sandbox Code Playgroud)