Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import error when using react-icons

Tags:

I have tried installing react icons, in my application I ran the npm command:

sudo npm install react-icons --save 

I didn't get any errors, apart from some optional dependencies, that where skipped

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected]  (node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for  [email protected]: wanted {"os":"darwin","arch":"any"} (current:  {"os":"linux","arch":"x64"}) 

Whenever I try to import some of the icons, I get an error

./src/components/SkiDaysCount.js Module not found: Can't resolve 'react-icons/lib/md' in '  '/home/kristoffer/ReactApps/navbar/src/components' 

here are my imports:

import {Terrain} from 'react-icons/lib/md' import {SnowFlake} from 'react-icons/lib/ti' import {Calender} from 'react-icons/lib/fa' 

Why am I getting this error?

EDIT:

i have also tried using the old syntax for importing, with the same issue as such:

import Calender from 'react-icons/lib/fa/calender' 
like image 867
Dedi Avatar asked Aug 10 '18 11:08

Dedi


People also ask

Can't import react-icons?

To solve the error "Module not found: Error: Can't resolve 'react-icons'", make sure to install the react-icons package by opening your terminal in your project's root directory and running the command npm install react-icons and restart your dev server.

Are react-icons SVG?

Luckily with React, we can create a new SVG component pretty easily that allows us to add our custom SVG icons anywhere we want.


1 Answers

When you use the v3 way of importing the icons, you should not have lib be a part of the import path.

The icons also have the icon library name as prefix for the export.

import { FaCalendar } from 'react-icons/fa' 
like image 83
Tholle Avatar answered Sep 20 '22 06:09

Tholle