已正确安装Material-UI却提示找不到模块的问题求助
Material-UI组件导入失败:模块找不到错误
已执行操作
- 按官网指引安装依赖:
npm install @mui/material @emotion/react @emotion/styled - 运行
npm ls验证安装,确认以下模块已安装:npm ls pwiki-frontend@0.1.0 /home/gilles/web-dev/pwiki-frontend ├── ... ├── @emotion/styled@11.10.5 ├── @mui/material@5.11.4 ├── @mui/styled-engine-sc@5.11.0 ├── ... - 在
src/index.js中导入组件:import TreeView from '@mui/lab/TreeView'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import ChevronRightIcon from '@mui/icons-material/ChevronRight'; import TreeItem from '@mui/lab/TreeItem';
启动开发服务器时的错误
执行npm start后,控制台抛出以下错误:
Module not found: Error: Can't resolve '@mui/lab/TreeView' in '/path/to/root-dir/src' ERROR in ./src/index.js 11:0-41 Module not found: Error: Can't resolve '@mui/lab/TreeView' in '/path/to/root-dir/src' ERROR in ./src/index.js 12:0-60 Module not found: Error: Can't resolve '@mui/icons-material/ExpandMore' in '/path/to/root-dir/src' ERROR in ./src/index.js 13:0-64 Module not found: Error: Can't resolve '@mui/icons-material/ChevronRight' in '/path/to/root-dir/src' ERROR in ./src/index.js 14:0-41 Module not found: Error: Can't resolve '@mui/lab/TreeItem' in '/path/to/root-dir/src'
无效的尝试
尝试设置NODE_PATH指定node_modules路径,不管是相对还是绝对路径都无法解决问题:
export NODE_PATH=./node_modules export NODE_PATH=/path/to/root_dir/node_modules
问题
哪里操作出错了?原本以为执行npm install就能正常使用,之前用其他模块也碰到过同样的问题。
内容的提问来源于stack exchange,提问作者BigBill
相关产品推荐
相关产品推荐

