简体   繁体   English

反应图标的导入错误。 找不到模块:无法解析“/usr/src/app/src/...”中的“react-icons/io”

[英]Import error for react-icons. Module not found: Can't resolve 'react-icons/io' in '/usr/src/app/src/...'

In my React app, which was built using create-react-app, I'm getting the error:在我使用 create-react-app 构建的 React 应用程序中,我收到错误消息:

Module not found: Can't resolve 'react-icons/io' in '/usr/src/app/src/components/analytics_components'.找不到模块:无法解析“/usr/src/app/src/components/analytics_components”中的“react-icons/io”。

The app has been working fine for a while but I just rebuilt it using Docker Compose and now it's not.该应用程序运行良好有一段时间了,但我只是使用 Docker Compose 重新构建了它,现在不是。

It seems like it's looking in the wrong directory, src instead of node_modules .它似乎在错误的目录中查找, src而不是node_modules

react-icons is definitely installed, npm list react-icons returns its version number. react-icons 肯定已安装, npm list react-icons返回其版本号。

I can see the io folder in node_modules/react-icons我可以在node_modules/react-icons 中看到io文件夹

The import statement:进口声明:

import { IoMdList } from "react-icons/io";

When I change the import to explicitly point to the node_modules directory, it works, but I didn't need to do this before nor do I need to for any other packages, which are still all working correctly:当我将导入更改为显式指向 node_modules 目录时,它可以工作,但我之前不需要这样做,也不需要任何其他包,这些包仍然可以正常工作:

import { IoMdList } from "../../../node_modules/react-icons/io";

Again you can install npm if you already installed that doesn't matter you can re-install your npm again without deleting current node module.同样,如果您已经安装了 npm,那么您可以再次安装 npm,这无关紧要,您可以在不删除当前节点模块的情况下再次重新安装您的 npm。 it works for me.这个对我有用。 command: npm install命令:npm 安装

您可以尝试删除您的节点模块文件夹并运行 cmd:npm install 或 yarn install 它可能会解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM