angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Bootstrap styles not loading

Open Harsangeet opened this issue 9 years ago • 45 comments

Hi,

I followed the steps for Global Library Installation https://github.com/angular/angular-cli#global-library-installation

  1. Installed [email protected] npm install bootstrap --save

  2. Then added the needed script files to to apps[0].scripts in angular-cli.json file:

 "scripts": [
    "../node_modules/bootstrap/dist/js/bootstrap.js"
    ],

and the Bootstrap CSS to the apps[0].styles array:

"styles": [
    "styles.css",
    "../node_modules/bootstrap/dist/css/bootstrap.css"
    ],
  1. Restarted ng serve

But the bootstrap styles are not loading

OS- Windows 7 Enterprise

angular-cli: 1.0.0-beta.21 node: 6.9.1 os: win32 x64

Harsangeet avatar Dec 05 '16 19:12 Harsangeet

@filipesilva Any idea?

hansl avatar Dec 05 '16 21:12 hansl

I'm using Bootstrap v4 with exactly this approach in beta.21 without any issue...

ghost avatar Dec 06 '16 09:12 ghost

I too. And when downgrade to bootstrap 3.3.7 - still work. (node 7.2.0)

vfedoriv avatar Dec 11 '16 17:12 vfedoriv

I have the same problem with bootstrap v3.3.7. I use the same config like you and it doesn't work now.

yanxiaodi avatar Dec 31 '16 14:12 yanxiaodi

I'm facing the same problem with angular-cli: 1.0.0-beta.21, node 7.2.1 and 4.0.0-alpha.6.

Bootstrap content is included in the generated styles.bundles.css file, but not available in the page

lukas-kloeppel avatar Jan 09 '17 08:01 lukas-kloeppel

I can confirm this behavior in 1.0.0-rc.0. I will try to create a reproduction and add it here, if I'm done.

Dinistro avatar Feb 27 '17 14:02 Dinistro

I found the problem in my case:

If you try to use a bundle from a linked npm package it breaks, because webpack works with the absolute path of the files and so, the exclude options of webpack aren't working anymore. I'm not sure if this is an issue of webpack or not.

There are more problems with linked projects, e.g. #5049, where this could be the reason of the failure.

Dinistro avatar Feb 28 '17 06:02 Dinistro

me also. the style is applied is i import bootstrap.css in styles.css. but i can not get it working in angular-cli.json > styles array.

lukestayreal avatar Mar 15 '17 11:03 lukestayreal

Closing as outdated. If this still happens, please let me know.

filipesilva avatar May 22 '17 14:05 filipesilva

I'm trying to follow a tutorial and I added the following to my .angular-cli.json

  "styles": [
    "../node_modules/bootstrap/dist/css/bootstrap.min.css",
    "styles.css"
  ],
  "scripts": [
    "../node_modules/bootstrap/dist/js/bootstrap.min.js"
  ],

But bootstrap does not show on the page.

Changing my index.html into this ugly mess works, but I'm pretty sure this webpack magic should handle it.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>MyApp</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<app-root>Loading...</app-root>
<script src="//code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>

I also have "bootstrap": "3.3.7" in my package.json. Not sure if that did anything. I'm new to this.

Zhuinden avatar Aug 10 '17 13:08 Zhuinden

@Zhuinden the example in https://github.com/angular/angular-cli/wiki/stories-global-lib is for Bootstrap 4, but you are using Bootstrap 3.

filipesilva avatar Aug 21 '17 10:08 filipesilva

I had this issue, then a good old exit and re-run of ng serve was all I needed to do.

alextait1 avatar Dec 06 '17 16:12 alextait1

@filipesilva ,Could u pls check my issue #9690?i am also facing similar type of issue. I am stuck in this issue from past 2 weeks,pls help me out.Thanks

faizy6641 avatar Feb 19 '18 23:02 faizy6641

I had the same problem with bootstrap 4. I uninstalled and installed version 3 and it worked npm -install bootstrap@3 --save .angular-cli.json "styles": [ "styles.css", "../node_modules/bootstrap/dist/css/bootstrap.css" ],

manojsgh avatar Feb 23 '18 04:02 manojsgh

Solution 1 (with Bootstrap installed) All you need to do is:

  1. Go to .angular-cli.json under the root directory of your angular app.

  2. Modify the styles array to include bootstrap before styles.css

"styles": [ "../node_modules/bootstrap/dist/css/bootstrap.min.css", "styles.css" ], Note: the path to bootstrap is relative to /src/index.html that's why you need "../" before node_modules.

  1. Exit the current session of ng serve and start it again.

Here is an awesome tutoral: https://www.youtube.com/watch?v=JYPyy-hvjYc&list=PL6n9fhu94yhXwcl3a6rIfAI7QmGYIkfK5&index=1#t=05m18s

Solution 2 (with Bootstrap referenced) All you need to is:

  1. Go to styles.css under the root directory of your angular app.

  2. Add this line at the top:

@import url('https://unpkg.com/[email protected]/dist/css/bootstrap.min.css'); Here is Angular docs: https://angular.io/guide/forms#create-an-initial-html-form-template

sherifkhattab13 avatar Mar 14 '18 03:03 sherifkhattab13

For me, I just added the following to my Angular-cli.json file, and it worked... remember, WebPack needs to know "where and what to include :) Be sure to restart "ng serve" "styles": [ "../node_modules/bootstrap/dist/css/bootstrap.min.css", "styles.css" ],

VerticalWorks avatar Mar 16 '18 15:03 VerticalWorks

Solution of manojsgh worked for me too.

ManojSonowal avatar Apr 07 '18 11:04 ManojSonowal

I have resolved this by reading the link provided by @filipesilva

mutantkeyboard avatar Apr 13 '18 08:04 mutantkeyboard

Thanks @alextait1 !! Your method worked for me.......

nadyscoolcodes avatar Apr 27 '18 10:04 nadyscoolcodes

Restart npm server

irfanakbar47 avatar May 01 '18 20:05 irfanakbar47