[英]React js - Unable to use react-icons, Module not found '../lib'
This is my first post on stackoverflow so I will try my best to keep it short, sweet, and detailed enough to hopefully find some assistance.这是我关于 stackoverflow 的第一篇文章,所以我会尽力保持简短、亲切和详细,希望能找到一些帮助。
I'm currently trying to learn React js and when I try to install react-icons
and import an Icon, my dev server is just crashing.我目前正在尝试学习 React js,当我尝试安装
react-icons
并导入图标时,我的开发服务器崩溃了。
npm install react-icons
{
"name": "ecostrategy",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"bootstrap": "^5.1.1",
"react": "^17.0.2",
"react-bootstrap": "^2.0.0-rc.0",
"react-dom": "^17.0.2",
"react-icons": "^4.3.0",
"react-router-dom": "^5.3.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.2"
},
import { FaGithub } from "react-icons/fa";
npm run start
Failed to compile. npm run start
编译失败。./node_modules/react-icons/fa/index.esm.js
./node_modules/react-icons/fa/index.esm.js
Module not found: Can't resolve '../lib' in 'D:\name\school\semester\class\project\node_modules\react-icons\fa'找不到模块:无法在“D:\name\school\semester\class\project\node_modules\react-icons\fa”中解析“../lib”
I've also tried npm install react-icons --save
and based on the error saying it can't resolve '../lib' I even just took a guess and tried npm install lib
which didn't work.我也试过
npm install react-icons --save
并根据错误说它无法解析 '../lib' 我什至只是猜测并尝试npm install lib
但没有用。 Uninstalling and reinstalling react-icons
didn't help either.卸载并重新安装
react-icons
也无济于事。
I deleted my node_modules
folder and ran npm install
again, this didn't fix the problem.我删除了我的
node_modules
文件夹并再次运行npm install
,这并没有解决问题。 My output after running npm install
was:运行
npm install
后我的 output 是:
added 1987 packages from 789 contributors and audited 1990 packages in 103.053s
添加了来自 789 个贡献者的 1987 包,并在 103.053 秒内审核了 1990 包
153 packages are looking for funding153个包裹正在寻找资金
runnpm fund
for details跑
npm fund
了解详情
found 3 moderate severity vulnerabilities发现 3 个中等严重程度的漏洞
runnpm audit fix
to fix them, ornpm audit
for details运行
npm audit fix
来修复它们,或运行npm audit
了解详情
When I try npm audit fix
it says something about not being able to solve them automatically, and npm fund
gives me just a list.当我尝试
npm audit fix
时,它说无法自动解决它们,而npm fund
只给我一个列表。
Apparently there's a problem with react-icons v4.3.0.显然 react-icons v4.3.0 有问题。 See this issue: https://github.com/react-icons/react-icons/issues/490
看到这个问题: https://github.com/react-icons/react-icons/issues/490
The solution is to downgrade to v4.2.0.解决方案是降级到 v4.2.0。 Try setting this line in your package.json:
尝试在您的 package.json 中设置此行:
"react-icons": "4.2.0",
Then remove node_modules
and run npm install
again.然后删除
node_modules
并再次运行npm install
。
This essentially "pins" the version of react-icons
to 4.2.0
.这实质上将
react-icons
的版本“固定”到4.2.0
。 It will never install another version.它永远不会安装另一个版本。 So, you'll want to keep an eye on the package. I'm sure a fix will be pushed soon.
因此,您需要密切关注 package。我相信很快就会推出修复程序。 After that you can set the version back to
"^4.3.0"
(or "^4.4.0"
if that's the fixed version) and see if it's resolved.之后您可以将版本设置回
"^4.3.0"
(如果是固定版本则为"^4.4.0"
)并查看是否已解决。
UPDATE: Apparently this has been fixed in react-icons
v4.3.1.更新:显然这已在
react-icons
v4.3.1 中修复。 So you can set this line in package.json back to:因此,您可以将 package.json 中的这一行设置回:
"react-icons": "^4.3.1",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.