-
Notifications
You must be signed in to change notification settings - Fork 12.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Defining icons from strings in React works, but there is always the 'Could not find icon' error message #19193
Comments
I have this same issue in NextJS and notice it more now with React 18 since the SSR portion gets |
Hey @tm1000 and @Stephcraft ! What happens if you change the code to this: import { fas } from '@fortawesome/free-solid-svg-icons'
import { far } from '@fortawesome/free-regular-svg-icons'
import { fab } from '@fortawesome/free-brands-svg-icons'
const { library } = require("../../node_modules/@fortawesome/fontawesome-svg-core")
library.add(fab)
library.add(fas)
library.add(far) (Yes I know I'm using (And here's a codesandbox to play around with: https://codesandbox.io/s/zen-chihiro-ku0do2?file=/pages/index.js) |
Sorry, I do not know NextJS. As far as I can tell, it is a framework based on React If this is the case, then the react-fontawesome component component is required to make font awesome work So I'm asking if there is there, by any chance, an answer to this issue on the react-fontawesome repository at https://github.com/FortAwesome/react-fontawesome/ or if this issue belongs to there |
My guess is that the Library singleton is not working correctly with SSR. We'd need to involve the Next.js folks in order to figure this out probably. I'd recommend the workaround of avoiding the import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faBars } from '@fortawesome/free-solid-svg-icons';
export default function Home() {
return <>
<FontAwesomeIcon icon={faBars} fixedWidth color="black" />
</>;
} |
I found the solution: import { library } from '@fortawesome/fontawesome-svg-core'
import { fas } from '@fortawesome/free-solid-svg-icons'
import { far } from '@fortawesome/free-regular-svg-icons'
import { fab } from '@fortawesome/free-brands-svg-icons'
library.add(fab)
library.add(fas)
library.add(far) Make sure all these packages are up to date, you can do so with
My problem I believe was that I did not have the import { library } from '@fortawesome/fontawesome-svg-core' I had to do like this: import { library } from "../../node_modules/@fortawesome/fontawesome-svg-core" Updating all the packages to the latest solved the annoying error message, allowed me to import the 'proper' way and gave me access to the latest icons available (sometimes icons did not appear because they did not exist with the version I had) @robmadole in my case, the reason I need to specify icons by string is so that I can define them in some sort of external file (json, yml, txt) so it can be deserialized and displayed. |
Apparently there's a related issue already open. #19348 |
This works for me, thanks a lot |
Bug description
When you do this for example:
and I even add every icon to the font awesome react
library
object. I've tried two different ways, same outcome:The icons do display, but the error message is still present:
Reproducible test case
No response
Screenshots
No response
Font Awesome version
v6.0.0
Serving
Other (as specified in the bug description)
Implementation
SVG+JS, Other (as specified in the bug description)
Browser and Operating System
Web bug report checklist
The text was updated successfully, but these errors were encountered: