[英]Module not found: Can't resolve 'react-icons/ai'
I am learning ReactJS. But now I got a problem.我正在学习ReactJS。但是现在我遇到了一个问题。 I used this code
我用这个代码
import { AiOutlineShoppingCart } from "react-icons/ai"
But it is showing this error:但它显示此错误:
Module not found: Can't resolve 'react-icons/ai'
I am using sanity to build an eCommerce website cms.我正在使用 sanity 来构建电子商务网站 cms。 I tried to install react-icons with this code
我试图用这段代码安装反应图标
yarn add react-icons
and I have checked the packages.jeson file and react-icons are present in dependencies.并且我已经检查了 packages.jeson 文件并且 react-icons 存在于依赖项中。 Can anyone please tell me how can I solve this problem?
谁能告诉我如何解决这个问题?
Some extra info:一些额外的信息:
Firstly, you should be aware that not all icons are available.首先,您应该知道并非所有图标都可用。 I sometime try to import some icons and I get error.
我有时尝试导入一些图标,但我得到了错误。
Secondly, make sure you copy the code from the website to make sure you didnot misspell the name其次,确保您从网站复制代码,以确保您没有拼错名称
Futhermore, you can delete your node_module and remove react-icons from package.json file, then do yarn add react-icons
and do yarn to install all your packages again此外,您可以从 package.json 文件中删除您的 node_module 并删除 react-icons,然后执行
yarn add react-icons
并执行 yarn 以再次安装所有包
Lastly, you're to import from the library that owns the icon, ie if you're importing from AiFillAudio
, you're to import it from react-icons/ai
.最后,你要从拥有图标的库中导入,即如果你从
AiFillAudio
导入,你要从react-icons/ai
导入它。 eg.例如。
import { AiFillAudio } from react-icons/ai
. import { AiFillAudio } from react-icons/ai
。
I hope this help you out.我希望这可以帮助你。
try reinstalling with npm install react-icons --save
command尝试使用
npm install react-icons --save
命令重新安装
I figured it out.我想到了。 My react-icons are installed in sanity the folder.
我的反应图标安装在文件夹中。 So when I was importing AiOutlineShoppingCart from react-icons, my program was looking for react-icons inside node_module of my main file.
因此,当我从 react-icons 导入 AiOutlineShoppingCart 时,我的程序正在我的主文件的 node_module 中寻找 react-icons。 But it is stored node_module of sanity.
但它存储了健全的node_module。 So I have to declare the whole path .
所以我必须声明整个路径。
Working code is工作代码是
import { AiOutlineShoppingCart } from "../sanity/node_modules/react-icons/ai"
Here, "sanity" means sanity folder name.此处,“sanity”表示 sanity 文件夹名称。
Thanks, everyone for helping me.谢谢大家帮助我。
This sometimes occurs when you install dependencies in the wrong directory.当您在错误的目录中安装依赖项时,有时会发生这种情况。
let's say you run npm i package-x
outside your project directory假设您在项目目录外运行
npm i package-x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.