Bower installs same package different in file stru

2019-08-18 02:39发布

问题:

We have a TeamCity build server running on three different buildusers with the same configuration. We have set up a angular/grunt project using yeoman

Update 6

Added a bower issue https://github.com/bower/bower/issues/1709

How come bower sometimes installs for example angular-animate with the structure:

bower_components/angular-animate/bower-angular-animate-1.3.13/angular-animate.js

and sometimes it puts the content of the bower-angular-animate-1.3.13 in the root so the structure looks like this:

bower_components/angular-animate/angular-animate.js

The first ones makes our test fails of course..

Anyone have a clue? It's always the same packages which get the extra directory. And locally it always works.

Update:

Seems like when we run bower it doesn't find the main js file in the packages bower.json and it looks like that could be the issue. But I don't know how to fix it.

Update 2:

It looks like bower doesn't find the main key in the bower.json for example:

[09:27:40]bower angular-animate#1.3.13          invalid-meta angular-animate is missing "main" entry in bower.json
[09:27:40]bower angular-animate#1.3.13          invalid-meta angular-animate is missing "ignore" entry in bower.json

So what could cause the difference in finding the main?

Update 3:

If I understand it correct the .bower.json file is created by bower after downloading and extracting the archive. Now I have notice that there are differences in the .bower.json file. In the generated .bower.json file the main and ignore is missing. And also the archive is extracted different as mentioned above.

This package fails:

[pejn@bx0023 1.3.13]$ more .bower.json
{
    "name": "angular-animate",
    "homepage": "https://github.com/angular/bower-angular-animate",
    "version": "1.3.13",
    "_release": "1.3.13",
    "_resolution": {
        "type": "version",
        "tag": "v1.3.13",
        "commit": "f18cb98590471ad9c1e5ae0e57178e9ecb8d384c"
    },
    "_source": "https://github.com/angular/bower-angular-animate.git",
"_target": "1.3.13"
}

And this works:

[pejn@bx0023 1.3.13]$ more .bower.json
{
    "name": "angular-animate",
    "version": "1.3.13",
    "main": "./angular-animate.js",
    "ignore": [],
    "dependencies": {
            "angular": "1.3.13"
    },
    "homepage": "https://github.com/angular/bower-angular-animate",
    "_release": "1.3.13",
    "_resolution": {
        "type": "version",
        "tag": "v1.3.13",
        "commit": "f18cb98590471ad9c1e5ae0e57178e9ecb8d384c"
    },
    "_source": "https://github.com/angular/bower-angular-animate.git",
    "_target": "1.3.13"
}

Update 4:

Adding my bower.json

{
  "name": "App",
  "version": "0.0.1",
  "dependencies": {
    "angular": "1.3.13",
    "json3": "3.3.0",
    "es5-shim": "4.0.0",
    "bootstrap": "3.2.0",
    "angular-animate": "1.3.13",
    "angular-cookies": "1.3.13",
    "angular-resource": "1.3.13",
    "angular-route": "1.3.13",
    "angular-sanitize": "1.3.13",
    "angular-touch": "1.3.13",
    "angular-cache": "3.2.5",
    "modernizr": "2.8.3",
    "jquery": "2.1.3",
    "jquery-ui": "1.11.3",
    "angular-bootstrap": "0.12.0",
    "angular-local-storage": "0.1.5",
    "highstock-release": "2.0.4",
    "moment": "2.9.0",
    "moment-timezone": "0.3.0",
    "angular-ui-sortable": "0.13.3",
    "angular-ui-utils": "bower-unique"
  },
  "devDependencies": {
    "angular-mocks": "1.3.13",
    "angular-scenario": "1.3.13"
  },
  "appPath": "app",
  "resolutions": {
    "angular": "1.3.13"
  }
}

Update 5

I runned the tests for bower on the buildserver and as I can see it looks like I have a proxy/permission problem. Looks like we get a 403. I include parts of the output for the boer tests below:

[18:27:57] [0m  1) UrlResolver .hasNew should resolve to false if cache headers haven't changed:
[18:27:57] [0m [31m     Uncaught Error: expected true to equal false [0m [90m
...
[18:27:57] [0m  2) UrlResolver .hasNew should resolve to true if server responds with 304 (ETag mechanism):
[18:27:57] [0m [31m     Uncaught Error: expected true to equal false [0m [90m
...
[18:27:57] [0m  3) UrlResolver .hasNew should work with redirects:
[18:27:57] [0m [31m     Uncaught Error: expected true to equal false [0m [90m
...
[18:27:57] [0m  4) UrlResolver .resolve should download file, renaming it to index:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  5) UrlResolver .resolve should extract if source is an archive:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  6) UrlResolver .resolve should extract if source is an archive (case insensitive):
[18:27:57]
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  7) UrlResolver .resolve should copy extracted folder contents if archive contains only a folder inside:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  8) UrlResolver .resolve should extract if source is an archive and rename to index if it's only one file inside:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
[18:27:57]      at createError (/mnt/ext4/builduser7/build-agent-work-dir/1f8c068934a7bbe0/node_modules/bower/lib/util/createError.js:4:15)
[18:27:57]      at Request.<anonymous> (/mnt/ext4/builduser7/build-agent-work-dir/1f8c068934a7bbe0/node_modules/bower/lib/util/download.js:45:40)
[18:27:57]      at Request.emit (events.js:117:20)
[18:27:57] [33mWarning: Task "simplemocha:full" failed.  Use --force to continue. [39m
[18:27:57]      at Request.onResponse (/mnt/ext4/builduser7/build-agent-work-dir/1f8c068934a7bbe0/node_modules/bower/node_modules/request/request.js:1085:10)
...
[18:27:57] [0m  9) UrlResolver .resolve should extract if source is an archive and not rename to index if inside it's just a just bower.json/component.json file in it:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
....
[18:27:57] [0m  10) UrlResolver .resolve should rename single file from a single folder to index when source is an archive:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
....
[18:27:57] [0m  11) UrlResolver .resolve should extract if response content-type is an archive:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
....
[18:27:57] [0m  12) UrlResolver .resolve should extract if response content-disposition filename is an archive:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  13) UrlResolver .resolve should save the release if there's a E-Tag:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  14) UrlResolver .resolve should allow for query strings in URL:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  15) UrlResolver .resolve should save cache headers:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
....
[18:27:57] [0m  16) UrlResolver .resolve should work with redirects:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
....
[18:27:57] [0m  17) UrlResolver .resolve content-disposition validation should work with and without quotes:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  18) UrlResolver .resolve content-disposition validation should not work with partial quotes:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  19) UrlResolver .resolve content-disposition validation should not work if the filename contain chars other than alphanumerical, dashes, spaces and dots:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  20) UrlResolver .resolve content-disposition validation should trim leading and trailing spaces:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  21) UrlResolver .resolve content-disposition validation should not work if the filename ends with a dot:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  22) UrlResolver .resolve content-disposition validation should be case insensitive:
[18:27:57] [0m [31m     Uncaught Error: Status code of 403 [0m [90m
...
[18:27:57] [0m  23) GitResolver ._cleanup should remove the .git folder from the temp dir:
[18:27:57] [0m [31m     Uncaught Error: ENOENT, lstat '/mnt/ext4/builduser7/build-agent-work-dir/1f8c068934a7bbe0/node_modules/bower/.git' [0m [90m
...
[18:27:57] [0m  24) GitFsResolver .resolve should checkout correctly if resolution is a branch:
[18:27:57] [0m [31m     Uncaught Error: Tag/branch some-branch does not exist [0m [90m
...
[18:27:57] [0m  25) GitFsResolver .resolve should leave the original repository untouched:
[18:27:57] [0m [31m     Uncaught Error: Tag/branch some-branch does not exist [0m [90m
...
[18:27:57] [0m  26) GitFsResolver .resolve should copy source folder permissions:
[18:27:57] [0m [31m     Uncaught Error: Tag/branch some-branch does not exist [0m [90m
...
[18:27:57] [0m  27) GitFsResolver #refs should resolve to the references of the local repository:
[18:27:57]
[18:27:57]       [31mUncaught Error: expected [ '0a7daf646d4fd743b6ef701d63bdbe20eee422de refs/tags/0.0.1',
...
[18:27:57] [0m  28) GitFsResolver #refs should cache the results:
[18:27:57]
[18:27:57]       [31mUncaught Error: expected [ '0a7daf646d4fd743b6ef701d63bdbe20eee422de refs/tags/0.0.1',
...
[18:27:57] [0m  29) GitRemoteResolver .resolve should checkout correctly if resolution is a branch:
[18:27:57] [0m [31m     Uncaught Error: Tag/branch some-branch does not exist [0m [90m
....
[18:27:57] [0m  30) GitRemoteResolver #refs should resolve to the references of the remote repository:
[18:27:57]
[18:27:57]       [31mUncaught Error: expected [ '0a7daf646d4fd743b6ef701d63bdbe20eee422de refs/tags/0.0.1',
...
[18:27:57] [0m  31) GitRemoteResolver #refs should cache the results:
[18:27:57]
[18:27:57]       [31mUncaught Error: expected [ '0a7daf646d4fd743b6ef701d63bdbe20eee422de refs/tags/0.0.1',
...
[18:27:57] [0m  32) GitHub .constructor should ensure .git in the source:
[18:27:57] [0m [31m     Error: expected 'https://github.com/twitter/bower.git' to equal 'git://github.com/twitter/bower.git' [0m [90m
...
[18:27:57] [0m  33) resolverFactory should recognize git remote endpoints correctly:
[18:27:57] [0m [31m     Uncaught Error: expected 'https://github.com/bower/bower.git' to equal 'git://github.com/bower/bower.git' [0m [90m
...
[18:27:57] [0m  34) resolverFactory should recognize GitHub endpoints correctly:
[18:27:57] [0m [31m     Uncaught Error: expected 'https://github.com/user/project.git' to equal 'git://github.com/user/project.git' [0m [90m
...
[18:27:57] [0m  35) resolverFactory should recognize registry endpoints correctly:
[18:27:57] [0m [31m     Uncaught Error: expected 'https://github.com/IndigoUnited/dejavu.git' to equal 'git://github.com/IndigoUnited/dejavu.git' [0m [90m
...
[18:27:57] [0m  36) resolverFactory should use the configured shorthand resolver:
[18:27:57] [0m [31m     Uncaught Error: expected 'https://github.com/bower/bower.git' to equal 'git://github.com/bower/bower.git' [0m [90m

回答1:

We ran into the same issue, it had to do with the tmp directory that was used by bower being on nfs storage. Verify that your tmp dir (either specified by "tmp" in .bowerrc or env var TMP_DIR) isn't on nfs mounted storage.