Font Awesome with React and Typescript
See original GitHub issueI’m not quite sure if this is the right place to post. I’m try to bring up a new project using react and typescript using font awesome. I’ve been using react and font-awesome for over a year and am a font-awesome pro subscriber (user?, member?).
I’m starting from the standard create-react-app (with typescript options) and the starter app runs fine. However after adding font-awesome and fontawesome-react things go badly. I’ve spend an entire day fighting with various errors trying to get this to work.
I’m using react 16.3; typescript 2.8.3
From my package.json here is the font-awesome stuff I have loaded:
"dependencies": {
"@fortawesome/fontawesome": "^1.1.5",
"@fortawesome/fontawesome-free-solid": "^5.0.10",
"@fortawesome/react-fontawesome": "0.0.18",
"@types/react-fontawesome": "^1.6.2",
In my App’s main file (App.tsx created by create-react-app), my current iteration has the following lines at the start of the file:
import faCoffee from "@fortawesome/fontawesome-free-solid/faCoffee";
import FontAwesomeIcon from "@fortawesome/react-fontawesome"
and in my render method I return:
<FontAwesomeIcon icon={faCoffee} />
The compiler errors are:
Module '"/Users/rich2129/Documents/src/zconsole2/node_modules/@fortawesome/fontawesome-free-solid/faCoffee"' has no default export.
File '/Users/rich2129/Documents/src/zconsole2/node_modules/@fortawesome/fontawesome-free-solid/faCoffee.d.ts' is not a module.
Could not find a declaration file for module '@fortawesome/react-fontawesome'. '/Users/rich2129/Documents/src/zconsole2/node_modules/@fortawesome/react-fontawesome/index.js' implicitly has an 'any' type.
Try `npm install @types/fortawesome__react-fontawesome` if it exists or add a new declaration (.d.ts) file containing `declare module 'fortawesome__react-fontawesome';`
File '/Users/rich2129/Documents/src/zconsole2/node_modules/@fortawesome/react-fontawesome/index.d.ts' is not a module.
I have tried changing my tsconfig.json to add (and remove) ‘allowSyntheticDefaultImports’. I’ve tried prerelease versions of the components.
I’m running out of ideas (and posts on here and stackoverflow to try). Any help would be appreciated. Thanks in advance.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (2 by maintainers)
Do you have a React/TypeScript example that uses @fortawesome/fontawesome-pro?
I think the only thing you need to do is bump the version
@fortawesome/fontawesome
so that the typescript typings are included (but you might need to check to be sure)Here is my setup that has been working for three months
package.json
index.tsx
./core/common/icon-library