Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bower Loading devDependencies in Production?

Short Version

My project requires angular-leaflet, and angular-leaflet has a long list of devDependencies, including jQuery 2. I don't want jQuery 2--I want jQuery 1.x. How can I get bower to ignore the devDependencies of angular-leaflet and let me use jQuery 1?

Long Version

I am using bower 1.2.8. Here is a minimal bower.json that reproduces the problem for me:

{
  "name": "bower-test",
  "dependencies": {
    "jquery": "1.x",
    "angular": "1.2.x",
    "angular-leaflet": "0.7.x"
  }
}

Running bower install results in the following error:

Unable to find a suitable version for jquery, please choose one:
    1) jquery#1.x which resolved to 1.11.0 and has bower-test as dependants
    2) jquery#2.1.0 which resolved to 2.1.0 and has angular-leaflet#0.7.5 as dependants
    3) jquery#>= 1.9.0 which resolved to 2.1.0 and has bootstrap#3.0.3 as dependants

At the very least, I expected bower install --production to ignore devDependencies in angular-leaflet. But here's the result (identical to above):

Unable to find a suitable version for jquery, please choose one:
    1) jquery#1.x which resolved to 1.11.0 and has bower-test as dependants
    2) jquery#2.1.0 which resolved to 2.1.0 and has angular-leaflet#0.7.5 as dependants
    3) jquery#>= 1.9.0 which resolved to 2.1.0 and has bootstrap#3.0.3 as dependants

Why is bower not ignoring the devDependencies of angular-leaflet? Is there a way to make it do so?

like image 638
jchamberlain Avatar asked Mar 03 '14 19:03

jchamberlain


People also ask

What is Bower and npm?

The biggest difference is that npm does nested dependencies (but is flat by default) while Bower requires a flat dependency tree (puts the burden of dependency resolution on the user). A nested dependency tree means that your dependencies can have their own dependencies which can have their own, and so on.

Is git essential for installing Bower?

Install. Bower depends on Node. js and npm. Also make sure that git is installed as some bower packages require it to be fetched and installed.

How do you get the latest version of the dependencies as per the JSON file installed?

You can find the latest version of the npm added in package. json file. If you want to add the latest version either you can run npm install or npm install @latest .


1 Answers

I think the solution you are looking for is the resolutions section of bower.json though as to why devDependencies of your dependencies are even being analyzed is not clear to me.

{
  "name": "bower-test",
  "dependencies": {
    "jquery": "1.x",
    "angular": "1.2.x",
    "angular-leaflet": "0.7.x"
  },
  "resolutions": {
    "jquery": "1.x"
  }
}

Perhaps this is a slight difference from npm in that doing bower install xyz includes devDependencies unless the -p or --production parameter is specified, but even if it is specified it doesn't seem to get passed on to dependencies -- perhaps this is a bug.

UPDATE: The problem seems to be related to this particular package/setup using angular-leaflet. Other components do not have this issue. For example, bower install webmaker-analytics just fetches webmaker-analytics, not qunit even though it was listed in this package's devDependencies.

like image 55
jacobq Avatar answered Sep 20 '22 18:09

jacobq