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

已正确安装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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 10:50:39