Font-awesome: Cannot read property 'prefix' of undefined

Created on 27 Apr 2018  路  6Comments  路  Source: FortAwesome/Font-Awesome

Hello, first of all sorry for English, I'm using the google translator.
Well, I'm starting to use FontAwesome 5 Pro with Angular 5 and I'm having a hard time using the direct import of the icons (not the complete package).
When calling the command "ng serve -prod" it works perfectly, but when running only "ng-serve", that is, development environment, I'm getting the error "Can not read property 'prefix' of undefined."
I used "npm" to install the pro (token) packages as described at link
I also changed the tsconfig.js file and added the option "allowSyntheticDefaultImports": true in the "compilerOptions" block as recommended by some website (I can not remember which) so that ng recognizes the separate imports of the icons.

if I put just the following code, even without using the icon, the page already gives the error:

import fontawesome from '@fortawesome/fontawesome';
import faSquare from '@fortawesome/fontawesome-pro-solid/faSquare';

fontawesome.library.add(faSquare);

but if I change the import to:
import {faSquare} from '@fortawesome/fontawesome-pro-solid'
the error does not occur and everything works beautifully ...

image

image

image

image

Most helpful comment

@alesil-alexandre

change

import faSquare from '@fortawesome/fontawesome-pro-solid/faSquare';

to

import { faSquare } from '@fortawesome/fontawesome-pro-solid/faSquare';

All 6 comments

I'm having the same problem with react + jest + webpack

@alesil-alexandre

change

import faSquare from '@fortawesome/fontawesome-pro-solid/faSquare';

to

import { faSquare } from '@fortawesome/fontawesome-pro-solid/faSquare';

In 5.1.0, the packages were renamed so it should look like this:

import { faSquare } from '@fortawesome/pro-solid-svg-icons/faSquare';

Do NOT forget the curly brackets or you will get the prefix error.

Thanks.

The docs need to be updated to reflect this.

The docs don't state how to do this for pro:

import { faSquare } from '@fortawesome/pro-solid-svg-icons/faSquare';

here https://fontawesome.com/how-to-use/on-the-web/using-with/react

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vivekagr picture vivekagr  路  194Comments

mitch621 picture mitch621  路  180Comments

tinyoverflow picture tinyoverflow  路  402Comments

ivafrydkova picture ivafrydkova  路  176Comments

bhubbard picture bhubbard  路  169Comments