4

I successfully added Bootstap to an Angular project and wanted to do the same with MDBoostrap ( I don't know if Bootstrap will still be useful tho ? )

I followed the official procedure just here using the npm installation.

But when I try to import the style I have the following error

enter image description here

Here is my app.module.ts file :

import { BrowserModule } from '@angular/platform-browser';
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
/*Ajout Test du dossier ngx bootstrap*/
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import { ModalModule } from 'ngx-bootstrap/modal';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    /*Ajout*/
    MDBBootstrapModule.forRoot(),
    BsDropdownModule.forRoot(),
    TooltipModule.forRoot(),
    ModalModule.forRoot()
  ],
  schemas: [ NO_ERRORS_SCHEMA ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

my angular-cli.json file :

"index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [

        "../node_modules/font-awesome/scss/font-awesome.scss",
        "../node_modules/angular-bootstrap-md/scss/bootstrap/bootstrap.scss",
        "../node_modules/angular-bootstrap-md/scss/mdb-free.scss",
        "./styles.scss"
      ],
      "scripts": [
        "../node_modules/chart.js/dist/Chart.js",
        "../node_modules/hammerjs/hammer.min.js"
      ],

and the import in my style.scss file :

@import "../node_modules/bootstrap/dist/css/bootstrap.min.css"; //OK
@import "../node_modules/angular-bootstrap-md/scss/bootstrap/bootstrap.scss"; //OK
@import "../node_modules/font-awesome/scss/font-awesome.scss"; // ERROR : ../fonts/fontawesome-webfont.eot
@import "../node_modules/angular-bootstrap-md/scss/mdb-free.scss"; // ERROR : ../font.roboto.Robto-Bold.eot

Like I have commented the first 2 imports are OK but the 2 others throws errors.

Looking at the Error I have the sensation that the system is looking at a myProject/font repesitory that indeed doesn't exist but I really don't get why.

UPDATE :

I found that roboto.scss file use a relative URL

@font-face {
font-family: "Roboto";
src: local(Roboto Thin), url('#{$roboto-font-path}Roboto-Thin.eot');
src: url("#{$roboto-font-path}Roboto-Thin.eot?#iefix") format('embedded-opentype'),
    url("#{$roboto-font-path}Roboto-Thin.woff2") format("woff2"),
    url("#{$roboto-font-path}Roboto-Thin.woff") format("woff"),
    url("#{$roboto-font-path}Roboto-Thin.ttf") format("truetype");

font-weight: 200;

}

where $roboto-font-path = ../fonts/roboto/. That clearly seems to be the problem.

It could be resolved using the resolve-url-loader and changing the configuration to

{
test: /\.scss$/,
loaders: ['style', 'css', 'resolve-url', 'sass?sourceMap']
}

but using angular-cli it can't be my case.

UPDATE 2 :

In fact it works !

The @import.... in the styles.scss file are useless.

The big mistake I made was trying to use an Mdb pro component and testing my configuration on it... I'm sorry guys.

Thanks for your help.

Y.Uzumaki
  • 119
  • 1
  • 3
  • 12

1 Answers1

3

Uzumaki,

First thing: Which operating system do you use? Windows, Linux or Mac?

Second thing: Did you create your project with --style=scss parameter?

Follow these steps to make it work properly:
ng new name --style=scss

then install the package:

npm install angular-md-bootstrap --save

then add imports to app.module.ts:

import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { MDBBootstrapModule } from 'angular-bootstrap-md';

then add styles and scripts locations to tsconfig.app.json file:

"styles": [
"../node_modules/font-awesome/scss/font-awesome.scss",
"../node_modules/angular-bootstrap-md/scss/bootstrap/bootstrap.scss",
"../node_modules/angular-bootstrap-md/scss/mdb-free.scss",
"./styles.scss"
],
"scripts": [
"../node_modules/chart.js/dist/Chart.js",
"../node_modules/hammerjs/hammer.min.js"
],

then install additional libraries using:

npm install -–save chart.js@2.5.0 font-awesome hammerjs

then to tsconfig.json file in root directory add:

"include": ["node_modules/angular-bootstrap-md/**/*.ts",  "src/**/*.ts"],

and for tsconfig.app.json file in /src directory i added:

"include": [ "**/*.ts", "../node_modules/angular-bootstrap-md/index.ts" ]

All should work fine now.


If you haven't created the project with --style=scss attribute, you have to do the following:

ng set defaults.styleExt scss

And change every extension from .css to .scss. For my project, I have changed files:

src/styles.css -> src/styles.scss,

src/app/app.component.css -> src/app/app.component.scss

And in src/app/app.components.ts

stylesUrls ['./app.component.css'] -> stylesUrls: ['./app.component.scss']

Now everything should work fine even if you haven't created your project using --styles=scss.

For your existing projectdDelete from app.module.ts these lines:

import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import { ModalModule } from 'ngx-bootstrap/modal';

Best Regards,
Damian from MDBootstrap

Sebastian Kaczmarek
  • 8,120
  • 4
  • 20
  • 38
Bloodcast69
  • 226
  • 1
  • 3
  • 10
  • I wanted to add MDBootstrap on an existing project so I tried the 2nd solutions but unfortunately it didn't work for me. I still have the exact same error. I don't understand where it's looking for the `font/roboto/Roboto-Bold.eot` file. I may have to start from scratch by using the `ng new name --style=scss` command but try to avoid it for the moment – Y.Uzumaki Feb 14 '18 at 13:22
  • Uzumaki do you have some .css files in your src or src/app directory? If not, try one more time type npm install with your auth key. – Bloodcast69 Feb 15 '18 at 13:35
  • The problem was the import in my styles.scss file. In fact I don't have to import them here for MDBoostrap to work. MoreoverI tried to use a MDBootstrap pro component so I thought it wasn't working but in fact it was ok...Thank you – Y.Uzumaki Feb 15 '18 at 14:49
  • I am getting npm ERR! code E404 npm ERR! 404 Not Found - GET https://registry.npmjs.org/angular-md-bootstrap - Not found – user123456 Jan 27 '22 at 11:17