Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular2-cli gives @multi styles error

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
like image 596
codestruggle Avatar asked Oct 13 '16 15:10

codestruggle


3 Answers

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

like image 148
Noopur Dabhi Avatar answered Nov 12 '22 00:11

Noopur Dabhi


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

like image 42
atfede Avatar answered Nov 11 '22 23:11

atfede


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

like image 6
Roger Perez Avatar answered Nov 11 '22 23:11

Roger Perez