Alex
Alex

Reputation: 21

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";

Upvotes: 2

Views: 16808

Answers (5)

user23390727
user23390727

Reputation:

This question has been here for a while, I'll just share my solution in case someone still needs it.

Create a file called "all.js" with the following content, save the file to "node_modules\react-icons".

By right, the file should be created by "npm install" or "yarn install", but if it was not created correctly, just create it manually.

export * from './fa';
export * from './io';
export * from './io5';
export * from './md';
export * from './ti';
export * from './go';
export * from './fi';
export * from './gi';
export * from './wi';
export * from './di';
export * from './ai';
export * from './bs';
export * from './ri';
export * from './fc';
export * from './gr';
export * from './hi';
export * from './si';
export * from './im';
export * from './bi';
export * from './cg';
export * from './vsc';

Upvotes: 0

Kaan Ateşel
Kaan Ateşel

Reputation: 470

In my case I tried to import single icon like following:

import { GrLogout } from "react-icons/gr/GrLogout";

it couldn't find the icon the true way is

import { GrLogout } from "react-icons/gr";

importing all lib and then getting single icon.

Upvotes: 0

MaNi Razavizadeh
MaNi Razavizadeh

Reputation: 31

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

Upvotes: 2

Saru Rajendran
Saru Rajendran

Reputation: 11

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

Upvotes: 1

Ritesh Rawal
Ritesh Rawal

Reputation: 1

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

Upvotes: 0

Related Questions