【React + Antd 教程】Failed to compile. Module not found: Can't resolve 'antd/dist'完美解决

本文介绍了在学习React + Antd过程中遇到的`Failed to compile. Module not found: Can't resolve 'antd/dist'`错误,分析了错误原因,并分享了解决此问题的具体步骤,通过更改导入路径成功编译并通过运行。

【React + Antd 教程】Failed to compile. Module not found: Can’t resolve 'antd/dist’完美解决

今天在学习React + Antd时

出了个不能编译的报错

Failed to compile.
./src/App.js
Module not found: Can't resolve 'antd/dist' in 'G:\***\src'

在这里插入图片描述
在这里插入图片描述
我是跟着视频敲得代码啊

怎么我这里就出错了呢 ? ? ?

在这里插入图片描述
于是

我在网上找寻各种解决办法

无 果

还得靠自己解决

首先

这个“Module not found: Can’t resolve ‘antd/dist’”报错的意思是:

'antd/dist’这个模块没有找到

于是我就查看该目录

在这里插入图片描述
这不是有这个模块吗? ? ? ? ? ?
在这里插入图片描述
在这里插入图片描述
然后

我想是不是不能直接导入这个包

导入整个包是不是就不能编译

所以是不是这里的问题呢?

于是

我更改导入为


                
前端项目的index.css文件中有@unocss preflights; @unocss default; 这个 运行项目后报错了Failed to compile, check the errors for troubleshooting. File: C:\Users\Lyun\Desktop\react-antd-admin-pro-main\src\index.css:1:1 × Module build failed: ╰─▶ × TypeError: Cannot read properties of undefined (reading '__esModule') │ at handleExports (C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@rspack\core\dist\cssExtractLoader.js:170:40) │ at C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@rspack\core\dist\cssExtractLoader.js:264:7 │ at C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@rspack\core\dist\index.js:6301:13 @ ./src/index.tsx File: C:\Users\Lyun\Desktop\react-antd-admin-pro-main\src\index.css:1:1 × Module build failed: ╰─▶ × Error: UnoCSS config not found: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:' │ at plugin (file:///C:/Users/Lyun/Desktop/react-antd-admin-pro-main/node_modules/@unocss/postcss/dist/esm.mjs:198:13) │ at async plugins (C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@unocss\postcss\dist\index.cjs:11:16) │ at async LazyResult.runAsync (C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@rsbuild\core\compiled\postcss\index.js:1088:17) │ at async Object.loader (C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@rsbuild\core\compiled\postcss-loader\index.js:99:20)
08-23
评论 6
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值