'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:

Module not found: Can't resolve 'react-icons/io' in '/usr/src/app/src/components/analytics_components'.

The app has been working fine for a while but I just rebuilt it using Docker Compose and now it's not.

It seems like it's looking in the wrong directory, src instead of node_modules.

react-icons is definitely installed, npm list react-icons returns its version number.

I can see the io folder in node_modules/react-icons

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:

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


Solution 1:[1]

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. it works for me. command: npm install

Solution 2:[2]

you can try delete your node module folder and run cmd:npm install or yarn install it may solve your problem

Solution 3:[3]

I just reinstall the command npm install react-icons and then it works.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Saru Rajendran
Solution 2 Ritesh Rawal
Solution 3 MaNi Razavizadeh