18

I started using angular2-cli recently and created a new project. I wanted to use bootstrap in my project hence I installed bootstrap and then wanted to import the bootstrap css file like it is shown in the the angular2-cli guide here. https://github.com/angular/angular-cli#global-library-installation After running ng serve I get the following error.

ERROR in multi styles Module not found: Error: Can't resolve '/home/krishna/angular2_migrate/webui/node_modules/bootstrap/dist/css/bootstrap.min.css' in '/home/krishna/angular2_migrate/webui/node_modules/angular-cli/models' @ multi styles

What am I doing wrong ?

Information about angular2-cli version

krishna@Krishna:~/angular2_migrate/webui$ ng version
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
angular-cli: 1.0.0-beta.17
node: 4.4.3
os: linux x64
codestruggle
  • 529
  • 3
  • 7
  • 17

16 Answers16

22

Add ../ before path.

In angular-cli.json,

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

Update

In angular7, there is angular.json file and you do not need to add ../ before path

Noopur Dabhi
  • 1,867
  • 25
  • 38
  • 6
    Almost worked for me. It worked only when I used `"./node_modules/bootstrap/dist/css/bootstrap.min.css"` – MWB Apr 27 '19 at 08:57
  • @MWB solution worked for me, placing "../" before path is throwing error, so replaced with "./" – Sagar M Jul 19 '20 at 13:50
9

In Angular 7 the file is called 'angular.json'.

Make sure you got the right extension set for the "styles" option. In my case I installed the Angular CLI with the SCSS option but the extension was set as SASS by default.

       "styles": [
          "src/styles.scss" // default was: src/styles.sass
        ],

enter image description here

atfede
  • 411
  • 6
  • 9
6

I am using Angular 6 so my filename is angular.json, but I was able to resolve the similar issue by removing the "../" path that it was asking for. Below is my setup for adding bootstrap and jquery to my angular app.

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

Note: for jquery i needed the "../" while bootstap did not require it.

Alternate based on issues I had:

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

Also, this article holds multiple alternate options on setting it .

https://medium.com/@rogercodes1/intro-to-angular-and-how-to-setup-your-first-angular-app-b36c9c3ab6ca

Roger Perez
  • 2,807
  • 29
  • 31
2

give the path like "./node_modules/bootstrap/dist/css/bootstrap.min.css" not like "../node_modules/bootstrap/dist/css/bootstrap.min.css"

"styles": 
[
    "./node_modules/bootstrap/dist/css/bootstrap.min.css",
    "src/styles.css"
]
Ariful Islam
  • 7,639
  • 7
  • 36
  • 54
Sundeep
  • 31
  • 2
1

In my case the error was was because i had

    "styles":[
      "styles.css"
    ]

in my .angular-cli.json

i solved it by manually typing the path of my all SCRIPTS and CSS ..i.e for example

    "styles":[
      "styles/bootstrap.scss",
      "styles/app.scss",
     ]

Paths in angular-cli.json are relative to the project root (src/ normally). For instance, you have the src/styles.css file, but in angular-cli.json it's listed only as styles.css.

Felix Runye
  • 2,135
  • 1
  • 20
  • 20
1

give the path like "./node_modules/bootstrap/dist/css/bootstrap.min.css" not like "../node_modules/bootstrap/dist/css/bootstrap.min.css"

"styles": 
[
    "./node_modules/bootstrap/dist/css/bootstrap.min.css",
    "src/styles.css"
]
Sundeep
  • 31
  • 2
1

Go to angular.json

navigate to styles and add another entry for bootstrap.min.css like

enter image description here

suraj garla
  • 322
  • 3
  • 6
0

here is the fix for me. in you current directory you have a hidden file called .angular-cli.json open that and change the "style.sass" to "style.css: run ng build and you are done.

BEFORE: enter image description here AFTER: enter image description here

grepit
  • 21,260
  • 6
  • 105
  • 81
0

The solution below worked for me, as it seems there is a bug in bootstrap 4.0:

npm uninstall bootstrap --save

then install

npm install bootstrap@3.3.7 --save
Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
user2181047
  • 1
  • 1
  • 4
0

I had same problem but I solve that issue by giving full path of the file like below "styles": [ "F:/Angular2Projects/Angular/myapp/node_modules/bootstrap/dist/css/bootstrap.min.css", "F:/Angular2Projects/Angular/my-app/src/styles.css" ],

jagdish khetre
  • 1,381
  • 2
  • 8
  • 15
0

You just need to add the below mentioned code in style.css

@import url('https://unpkg.com/bootstrap@3.3.7/dist/css/bootstrap.min.css');

Hope it helps

Yoshita Mahajan
  • 443
  • 4
  • 6
0

Copy and paste the following in your {}angular.json file should work perfect.

 "styles": [
          "node_modules/bootstrap/dist/css/bootstrap.min.css",
          "src/styles.css" ],
Dholu
  • 658
  • 7
  • 14
0

I got same error in angular 7 after installing primeng

I removed ./ from path in angular.json file rename "src/styles.scss" from "src/styles.css" and it works for me

0

In file angular.json , I changed styles.sass to styles.scss .

I build successfully

that is navigate to src folder and see the extension of styles file

change it accordingly in angular.json styles object

Ever Think
  • 683
  • 8
  • 22
0

I had the same issue. I resolved it by uninstalling bootstrap

npm uninstall bootstrap --save

and then, installing it again

npm uninstall bootstrap --save

It worked for me.

Shankar
  • 2,890
  • 3
  • 25
  • 40
0

Full physical path to be given for node_modules .I have given full physical path for the css file and finally solve the issues