Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullInjectorError: No provider for FaConfig

Installed angular-fontawesome into angular app using npm like mentioned in github

Works fine in development mode. But gave error in production build.

Of course the initial error was

NullInjectorError: StaticInjectorError(Do)[qm -> t]: StaticInjectorError(Platform: core)[qm -> t]: NullInjectorError: No provider for t!

Had to change setting in angular.json to

"optimization": false,
...
"buildOptimizer": true,

to find out the actual error

NullInjectorError: StaticInjectorError(AppModule)[FaIconComponent -> FaConfig]: StaticInjectorError(Platform: core)[FaIconComponent -> FaConfig]: NullInjectorError: No provider for FaConfig!

How shall I resolve this.

The module has

import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';

Added to imports

  @NgModule({
  declarations: [...],
  imports: [
    ...
    FontAwesomeModule
  ],

And component has

import { faEllipsisV, ... } from '@fortawesome/free-solid-svg-icons';

like mentioned in how to guide.

Here are dependencies

  "dependencies": {
    "@angular/animations": "~8.2.11",
    "@angular/cdk": "~8.2.3",
    "@angular/common": "~8.2.11",
    "@angular/compiler": "~8.2.11",
    "@angular/core": "~8.2.11",
    "@angular/forms": "~8.2.11",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.2.11",
    "@angular/platform-browser-dynamic": "~8.2.11",
    "@angular/router": "~8.2.11",
    "@fortawesome/angular-fontawesome": "^0.6.0-alpha.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.25",
    "@fortawesome/free-solid-svg-icons": "^5.11.2",
    "bootstrap": "^4.3.1",
    "classlist.js": "^1.1.20150312",
    "hammerjs": "^2.0.8",
    "ngx-bootstrap": "^5.2.0",
    "ngx-cookie-service": "^2.2.0",
    "ngx-webstorage-service": "^4.1.0",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "web-animations-js": "^2.3.2",
    "zone.js": "~0.9.1"
  }

Angular Version 8.3.12.

like image 283
vipanth Avatar asked Nov 22 '19 09:11

vipanth


3 Answers

This is an issue in the latest version 0.6.0-alpha.0, which may get installed automatically when you don't specify the version.

https://github.com/FortAwesome/angular-fontawesome/issues/210

You can downgrade to version 0.5.0 to resolve this AOT build error:

npm i @fortawesome/[email protected]
like image 106
Bart Verkoeijen Avatar answered Oct 19 '22 20:10

Bart Verkoeijen


This error caused because of an updated version, as this issue still persists with 0.6.0-alpha.0, please downgrade your angular font-awesome library.

For example, use this command by specifying correct version :

npm i @fortawesome/[email protected]

Ps: Till angular8 It will work as I haven't tried this on angular8+

like image 28
Omkar Joshi Avatar answered Oct 19 '22 21:10

Omkar Joshi


Downgrading to 0.5.0 worked for me.

like image 1
Hassan Avatar answered Oct 19 '22 19:10

Hassan