import error when using react-icons - reactjs

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: fsevents#1.2.4
(node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for
fsevents#1.2.4: 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'

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'

After looking through the icon directories react-icons/[fa,ti,md] and looking at the index.dt.ts file for the new names of the icons I came up with your answer.
import { MdTerrain } from "react-icons/md";
import { TiWeatherSnow } from "react-icons/ti";
import { FaCalendarAlt } from "react-icons/fa";
To use the icons in your component use the tags:
<FaCalendarAlt />
<TiWeatherSnow />
<MdTerrain />
For an explanation look at the Migration from version 2-> 3 on the react-icon page.
https://www.npmjs.com/package/react-icons

Not all the fa icons are free. I was getting this error when I was trying to import the paid icon of pencil as below.
import { FaPencil } from 'react-icons/fa'
If you see here for all the fa icons, you can see that the pencil needs the pro license.
As I was not having a pro license, I was getting the error. But we can always use the free versions of pencil, and we just need to import it as below.
import { FaPencilAlt } from 'react-icons/fa'
<button><FaPencilAlt /></button>
You should also check the implementation of your version from here.

If you have installed the 3.0.5 version of react-icons, Do try :
For Pencil(Edit):
import {FaPencilAlt} from 'react-icons/fa'
For Trash Can (Delete):
import {FaTrash} from 'react-icons/fa'

import {FaHiking, FaRightAlign,...} from 'react-icons/fa'
from the v3 of react icons library '/libname' is mandatory.
libname as 'fa'-> fontawesome, 'fi'->feathericons. for more info visit
https://react-icons.netlify.com/#/

maybe you have to update the "react-icons" package.
command:
npm update react-icons

This can also be caused by typo error.
say
import {Haiking) from 'react-icons/fa'
instead of
import {Hiking) from 'react-icons/fa'

perhaps you are in yarn mode and you need to use yarn add instead of npm install to install a package.

import { FaCalendar } from 'react-icons/fa';
import { MdTerrain } from "react-icons/md";

Mine was such an easy fix after all. All I needed was the full import name of the icon, even if just one icon always put curly {} and that was it fixed!
How many times do I delete node modules, install #latest and then realise ist the curlies! :-)
import {GoMail} from "react-icons/go";

Related

Module not found: Can't resolve 'react-bootstrap/Media'

My MERN application is returning the error Module not found: Can't resolve 'react-bootstrap/Media'.
I am importing several react-bootstrap modules as shown:
import Image from "react-bootstrap/Image"
import Col from "react-bootstrap/Col"
import Media from "react-bootstrap/Media"
import Row from "react-bootstrap/Row"
import Button from "react-bootstrap/Button"
The remainder are working as expected. Any ideas why this one import wouldn't be found?
Thanks!
Check your node_modules and see if it's there
I was also having this issue. I had to downgrade my version of react-bootstrap to import the Media component.
npm install react-bootstrap#1.6.1
Looks like Media is changed to Card component in newer versions of react-bootstrap. https://react-bootstrap.github.io/components/cards/
You should use:
import Card from "react-bootstrap/Card"

attach icon issue from Fawesome

hope you can clarify this issue,
I am trying to use the Github Icon from fontawesome in react following the documentation:
link to documentation,
but I am having an issue and getting this error:
./src/components/FindMe/FindMe.jsx
Attempted import error: 'faGithub' is not exported from '#fortawesome/free-solid-svg-icons'.
My code is
//the imports from FA
import { FontAwesomeIcon } from '#fortawesome/react-fontawesome';
import { faGithub } from '#fortawesome/free-solid-svg-icons';
//the icon as per documentation
<FontAwesomeIcon icon={faGithub} />
I tried changing the capital letters but nothing, also using fabGithub but does not work, different ways to do it folowing the documentation but also nothing, I tried with other icons and it works.
Hope someone can clarify
edit
solved issue using this :
https://react-icons.github.io/react-icons/#/[enter link description here]2
FontAwesome have divided icons into separate npm packaged.
Github Icon is in different package: #fortawesome/free-brands-svg-icons
so first you would need to install that
npm install --save #fortawesome/free-brands-svg-icons
or
yarn add #fortawesome/free-brands-svg-icons
and then use it in your code:
import { faGithub } from '#fortawesome/free-solid-svg-icons';

Unable to import outlined svg icon component material-ui

I am using material icons in by react application.
I wanted to use circular check.
I could import and use the check_circle icon as follows
import CheckCircle from 'material-ui/svg-icons/action/check-circle';
There is another icon called circle_check_outline which I am unable to import by the normal import line
import CheckCircleOutline from 'material-ui/svg-icons/action/check-circle-outline';
It gives Can't resolve 'material-ui/svg-icons/action/check-circle-outline' error
I tried downloading the icon and render it as suggested in Marson Mao's answer to a similar question in stackoverflow
import SvgIcon from 'material-ui/SvgIcon';
import CheckCircleOutline from '../../assets/check-circle-outline.svg';
<SvgIcon>
{CheckCircleOutline}
</SvgIcon>
Then I got the following error
Uncaught TypeError: Cannot read property 'svgIcon' of undefined
at SvgIcon.render
I also tried Joey T 's answer in the same question. Installed #material/icons package using npm install #material-ui/icons#2.0.0-beta.1
and imported the icon as follows
import CheckCircleOutline from '#material/icons/CheckCircleOutline';
Still getting the error
Can't resolve '#material/icons/CheckCircleOutline'
I am using material-ui v0
The material-ui does not have check-circle-outline icon, hence it gives an error when importing. What you can do is get the latest icons from #material-ui/icons and then import them
Install the package by using the following command
npm install #material-ui/icons
Then import it,
import CheckCircleOutline from '#material-ui/icons/CheckCircleOutline';
Try this.
import CheckCircleoutline from '#material-ui/icons/CheckCircleOutline';
Use <CheckCircleoutline />

'Proptypes' is not defined

I'm setting up a new React with the help of: Create React App
However, I'm running into a linting issue. I'm receiving the following linting error 'PropTypes' is not defined. (no-undef).
Here is the code that is causing the issue:
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class Routers extends Component {
static propTypes = {
history: PropTypes.object.isRequired
};
...
I tried playing around with the react/prop-types rule, but to no avail.
Since react 15.5, PropTypes is included in a separate package, 'prop-types'.
So this line will help
import PropTypes from 'prop-types'
You can read more here
According to this issue comment.
It appears to be because you have installed eslint 4.x when you should just use the eslint version that is shipped with create-react-app. You should remove any eslint you have manually installed and use the one that comes with the repo.
I had the same problem on a project with eslint installed globally.
I solved this case by installing eslint manualy in the project:
npm i eslint --save
bye
jeff
Please Install prop-types
using this code:
npm install --save prop-types
If you're using <script> tags; you can add this tag:
<script src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.7.2/prop-types.min.js" integrity="sha512-ssNhh7jlzc+K93ckIlSXFHHz6fSFv0l619WOv8xbFNRbFOujbasb42LVMOggDrQR1ScJncoWb+KAJx1uF3ipjw==" crossorigin="anonymous"></script>
You can get the minified/non-minified and other version here
Good Luck...
Please install the prop-types npm package - react 1.15 and greater on separate package is created.
Here to install package
You can place the PropTypes just after the class (outside the class):
Routers.propTypes = {
history: PropTypes.object.isRequired
}

ReactJS + typescript - could not import react-autosuggest

I have problem with writing in TypeScript & ReactJS. I have no idea how to import external libraries and use them properly in the code.
I'm trying to use react-autosuggest in my project so I'm:
Installing react-autosuggest with npm install --save react-autosuggest
Installing typing for this library with typings install --global --save dt~react-autosuggest
going to file where I want to use this and trying to import that and use
Here I have problem, because I still have problems with importing it.
When I'm trying to import it with import * as autosuggest from 'react-autosuggest' I'm getting error
error TS2497: Module ''react-autosuggest'' resolves to a non-module entity and cannot be imported using this construct.
When I'm importing with import Autosuggest from 'react-autosuggest' another error appears:
error TS1192: Module ''react-autosuggest'' has no default export.
Could you guide me how to do it?
To fix your import use require:
import AutoSuggest = require("react-autosuggest");
new AutoSuggest();
The export of the module is done with the export = syntax. Refer to this SO for details on why you need to import this with require: https://stackoverflow.com/a/29598404/5324369

Resources