5

I can not seem to get bootstrap to load via the angular.json file

similar to this issue, however, nothing bootstrap related will load. However, ng build and ng serve seems to not report any isssues. Its just that then I browse to the page, its obvious that nothing is being styled.
Bootstrap 4.1.1 Navbar not working with Angular 6

[ note ] Rolling back to [email protected] seems to work just fine

package.json

{
  "name": "client-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "bootstrap": "^4.1.1",
    "core-js": "^2.5.4",
    "jquery": "^3.3.1",
    "popper": "^1.0.1",
    "popper.js": "^1.14.3",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^6.0.3",
    "@angular-devkit/build-angular": "~0.6.8",
    "typescript": "~2.7.2",
    "@angular/cli": "~6.0.8",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }

angular.json "

styles": [
          "./node_modules/bootstrap/dist/css/bootstrap.min.css",
          "src/styles.css"
        ],
        "scripts": [
          "./node_modules/jquery/dist/jquery.min.js",
          "./node_modules/popper.js/dist/umd/popper.min.js",
          "./node_modules/bootstrap/dist/js/bootstrap.min.js"
        ]

7 Answers 7

16

I faced this problem before and the solution is to make @import '../node_modules/bootstrap/dist/css/bootstrap.css'; in style.css file at the top of any code. so bootstrap will load successfully

Sign up to request clarification or add additional context in comments.

2 Comments

@Menna Ramadan, Do we need to import bootstrap.min.js as like css?
@Sricharan yes I think so If you need bootstrap js file in you application.
4

I just added it to an Angular 7 project and the steps were:

1- Installing bootstrap 4:

npm install bootstrap

2- Add the below import to the src\styles.css

@import '~bootstrap/dist/css/bootstrap.min.css';

2 Comments

This finally worked but why??? Why do i have to import it manually in the style.css, whats the usage of importing it in "styles" attribute in angular.json?
Honestly I asked the same question to myself but it was the way I had it working that time :( so wanted to share to help someone else :).
1

I propose to edit styles.css:

@import "~ bootstrap/dist/css/bootstrap.css";

if better solution very simple and effective

1 Comment

I think by this way (using a space after ~) you cause an error and bootstrap will not be loaded.
1

If bootstrap was updated/installed after rendering the app using 'ng serve', kill the process and recompile the app.

1 Comment

This should be the correct answer. After angular.json is changed to include scripts and styles, or otherwise, should kill and restart ng serve. I confirmed this by comparing the dist version in actual webserver (IIS) and confirmed that ng serve version is not updated even though the webserver version is updated.
0

Don't use @import '~bootstrap/dist/css/bootstrap.css'.

I have solve using below @import 'bootstrap/dist/css/bootstrap.css'; in styles.css

Comments

0

Importing bootstrap.css is totally unnecessary because it is duplication of process. I have solved it by removing bootstrap -Sometimes configurations could be for bootstrap 3 - then installing lastest version with npm install bootstrap solves my problem.

Comments

0

write @import '../node_modules/bootstrap/dist/css/bootstrap.css'; in style.css this will give you compile error after that write the old code as below to make it work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.