I have a bower.json file
{
"name": "example-project",
"private": true,
"dependencies": {
"angular": "1.2.14",
"angular-scenario": "1.2.14",
"angular-resource": "1.2.14",
"angular-ui-router": "0.2.10",
"angular-strap": "2.0.0"
}
}
When I run grunt (with grunt-bowercopy or grunt-bower-task) I get an error Fatal error: Unable to find suitable version for angular
When I run bower install it says it doesn't know which version of angular to use:
Unable to find a suitable version for angular, please choose one:
1) angular#1.2.14 which resolved to 1.2.14 and is required by angular-scenario#1.2.14, example-project
2) angular#>= 1.0.8 which resolved to 1.2.16 and is required by angular-ui-router#0.2.10
3) angular#~1.2.10 which resolved to 1.2.16 and is required by angular-strap#2.0.0
Prefix the choice with ! to persist it to bower.json
So that explains why grunt was failing - it had transitive dependencies and didn't know which one to select. So I choose 1 (!1 to persist). Now my bower.json looks like this:
{
"name": "example-project",
"private": true,
"dependencies": {
"angular": "1.2.14",
"angular-scenario": "1.2.14",
"angular-resource": "1.2.14",
"angular-ui-router": "0.2.10",
"angular-strap": "2.0.0"
},
"resolutions": {
"angular": "1.2.14"
}
}
Sweet! I run bower install again. This time it succeeds but removes the "resolutions" part. Now it just works for me without resolutions, but my coworkers will get the same error and have to go through the same process.
Why does it do this? Is there any way to stop it from happening?
-Update-
It seems that this is a bug. See bower issues https://github.com/bower/bower/issues/1061 and https://github.com/bower/bower/issues/1272. Hopefully the issue will get some attention and get resolved.
Upgrade to Bower 1.4.0 or greater where this issue is resolved.
Previous Answer:
A workaround suggested by edeustace (see https://github.com/bower/bower/issues/1061) is to add a script to your build (grunt, gulp, etc) that resets the resolutions as they should be after running bower. It's an ugly solution but should do the trick until the issue gets resolved.
Related
I listed (and/or installed) several dependencies with Bower inside the bower.json file and/or with
bower install https://github.com/username/project.git
That worked fine.
Now I can list all them with
bower list
and then I can pick the name of each dependency of my project and run
bower update dependency-name
Question: How can I bulk update all of them? Or do I have to write a shell script to loop through and update them?
You can update all by running bower update.
Use the -h flag on any command to see how you can use it. Eg bower update -h.
This process is a little slow but is secure because you can realize when your app gets broken.
lets say that you want to update bootstrap you just need to run bower install --save bootstrap and you bower.json file will be updated
Before
{
"name": "my-awesome-app",
"version": "0.0.0",
"dependencies": {
"bootstrap": "~3.0.0",
"requirejs": "~2.1.11",
"modernizr": "~2.8.2",
"jquery": "~2.1.1",
"underscore-amd": "~1.5.2",
"backbone-amd": "~1.1.0",
"require-handlebars-plugin": "~0.8.0"
}
}
After
{
"name": "my-awesome-app",
"version": "0.0.0",
"dependencies": {
"bootstrap": "~3.3.1",
"requirejs": "~2.1.11",
"modernizr": "~2.8.2",
"jquery": "~2.1.1",
"underscore-amd": "~1.5.2",
"backbone-amd": "~1.1.0",
"require-handlebars-plugin": "~0.8.0"
}
}
Used bower-update-all to update all bower dependencies in bower.json, as follows:
npm install -g bower-update-all
bower-update-all
If you want to force all dependencies to update you can use bower install --save --force. This is the same as bower install --save [dep1] [dep2] ...
The short version is bower i -S -f
I am using bower see dependencies from my bower.json below, so the question is I want bower to give a report of dependencies with newer version release but without installing it, for insatnce using npm-check-updates for npm give a nice list of dependencies that are outdated.
...
"dependencies": {
"angular": "1.3.0-beta.17",
"angular-animate": "1.3.0-beta.17",
"angular-mocks": "1.3.0-beta.17",
"angular-resource": "1.3.0-beta.17",
"angular-route": "1.3.0-beta.17",
"angular-ui-select2": "~0.0.5",
"underscore": "~1.x",
"bootstrap": "~3.x",
"components-font-awesome": "~4.x",
"angular-bootstrap": "~0.11.0",
"ng-grid": "~2.0.11",
"AngularJS-Toaster": "~0.4.6",
"intro.js": "~0.9.0",
"angular-intro.js": "~1.1.1"
},
...
You can just do bower ls and it'll tell you which packages are outdated. However there's discussion regarding adding an outdated command alias to be consistent with other package managers, included npm. You can voice your support here: https://github.com/bower/bower/issues/1138
I'm a github enterprise user and I'm using bower to point an internal repository to manage dependencies.
I have set up a repo and included a bower.json file in the root directory. It looks like this:
{
"name": "Axis",
"main": "Axis.js",
"version": "0.0.0",
"authors": [
"Nick Randall"
],
"description": "Chart Axis",
"keywords": [
"d3",
"d3.chart",
"axis"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"d3": "~3.4.6",
"d3.chart": "~0.2.0",
"lodash": "~2.4.1"
}
}
I'm trying to install the repo above as a dependency in a new project using "bower install Org/Axis" and the process hangs after the "Checkout" step. Am I doing something wrong or is this a bug?
My .bowerrc file looks like this:
{
"shorthand-resolver": "https://git.company.com/{{owner}}/{{package}}'.git"
}
and this is the response I get from the command line:
bower Axis#* not-cached https://git.company.com/Org/Axis.git#*
bower Axis#* resolve https://git.company.com/Org/Axis.git#*
bower Axis#* checkout v1.1.1
after that it just hangs there and never progresses.
About a year ago, there was an issue with bower hanging due to problems with the version of unzip. To see if your hanging may have the same cause you might try to install one of the dependencies individually. If an individual install doesn't hang you may have the same issue as before -- it occurred in the presence of certain combinations of node version and bower version. To try and load individually, consider for example:
bower install https://github.com/lodash/lodash.git
It turns out that this was a dumb mistake. I had my .bowerrc in the wrong location. Once I moved it to the root of my project, everything started working. I hope this helps somebody else!
I am downloading angular, angular-bootstrap and bootstrap with bower. Bootstrap has a dependency on jquery which is installed in the process. But i don't need it in my project as i am only using bootstrap's css.
So i tried to permanently remove the dependency on jquery with
bower uninstall jquery --save
It's uninstalling jquery, but the next time i make bower update, it's downloaded again.
Is there a way to tell bower to permanently skip a dependency ?
edit: I wish there was something like this:
"resolutions": {
"jquery": "no, thanks"
}
Pull request #1394 added official support for this feature and is present in bower version 1.6.3 and later. Check your version with bower -v, and run npm install -g bower to upgrade.
For reference, please see the .bowerrc official specification document. If this doesn't work for you, please file an issue with bower because it is a bug.
We use it like this in our .bowerrc such as the following:
{
"ignoredDependencies": [
"bootstrap",
"bootstrap-sass",
"bootstrap-sass-official"
]
}
We had a similar situation where we had Backbone depend on Underscore in its bower.json, but we're using Lo-Dash in its stead, so Bower was unnecessarily pulling down Underscore for each install. We have automated checks for 3rd party license compliance, so we didn't want anything we don't actually use.
I realize this isn't exactly what they're meant for, but Bower's install-hooks can be used to clean unneeded deps post-install (at least until Bower gets the sort of "no thanks" resolution you hinted at). In your .bowerrc:
{
"directory": "app/bower_components",
"scripts": {
"postinstall": "rm -rf app/bower_components/underscore"
}
}
It's a bit of a hack, but works.
Something you can do also in your bower.json file:
{
"dependencies": {
...
"bootstrap": "^3.2.0"
}
"overrides": {
"bootstrap": {
"dependencies": []
}
}
}
This means: remove all boostrap's dependencies, which is what you want since jquery is the only one (you can check with bower info bootstrap)
Add it to your .gitignore if you commit your dependencies. Otherwise leave it as it makes no difference. You should just use what you need and ignore the rest.
The above answers are correct but an additional solution is to use wiredep as explained in this answer:
grunt-bower-install: exclude certain components
After installing grunt-wiredep, you can add something similar to this to your Grunt.js to exclude jquery from being injected:
// Automatically inject Bower components into the app
wiredep: {
options: {},
app: {
src: ['<%= my.app %>/index.html'],
exclude: ['bower_components/jquery']
}
},
Bower will still download jquery unfortunately but at least you can tell it not to be included in the HTML src.
DISCLAIMER: This doesn't fix your particular problem, but it helped with mine, so maybe it'll help other people.
I'm using grunt-bower-task to pull the files into a lib directory. I wanted to exclude "angular" and just include "angular.js". One of my dependencies was pulling in "angular". In my bower.json I now have:
{
"name": "myapp",
"version": "0.0.1",
"dependencies": {
"angular.js": "1.3.15",
"angular-bootstrap": "0.13.0",
"angular-cookies": "1.3.15",
"angular-storage": "0.5.0",
"angular-ui-router": "0.2.15",
"mjolnic-bootstrap-colorpicker": "2.1"
},
"exportsOverride": {
"angular": {
"dump": "*.xxx"
},
"angular.js": {
"js": [ "*.js", "*.js.map" ],
"css": "*.css"
}
},
"resolutions": {
"angular": "1.3.15"
}
}
In my gruntfile.js I have:
bower: {
install: {
options: {
targetDir: './lib',
layout: 'byType',
install: true,
cleanTargetDir: true,
cleanBowerDir: false
}
}
},
This stops the "angular" files from being copied to the destination.
I have a project that depends on both:
jquery ~1.9.1
another project which in turn depends on jquery >=1.7.2
But when I run bower install, it ends up installing jquery 2.0.2.
This seems broken.
How do I either (a) make it correctly solve the constraints or (b) explicitly force a final version to be installed (workaround)?
You can add resolutions to the object in your bower.json file and specify the component name & version to automatically resolve the conflict when running bower commands.
Like this:
{
"name": "project-x",
"private": true,
"dependencies": {
"bootstrap-sass": "~3.3.7",
"modernizr": "~2.8.3",
"jquery": "~1.11.3"
},
"devDependencies": {},
"resolutions": {
"jquery": "~1.11.3"
}
}
Also you can run bower install and when bower will ask for "suitable version" (if interactive mode is on), prefix choice with !, so bower will save your choice into bower.json file.
use --force-latest
enter link description here