Node.js Heroku部署 – 无法执行后安装脚本安装Bower

将我的Node.js MEAN应用程序部署到heroku失败,并出现以下错误。 我无法弄清楚凉亭安装有什么问题

这是错误消息:

2606 info postinstall App@1.0.0 2607 verbose unsafe-perm in lifecycle true 2608 info App@1.0.0 Failed to exec postinstall script 2609 error App@1.0.0 postinstall: `./node_modules/bower/bin/bower install` 2609 error Exit status 1 2610 error Failed at the App@1.0.0 postinstall script. 2610 error This is most likely a problem with the App package, 2610 error not with npm itself. 2610 error Tell the author that this fails on your system: 2610 error ./node_modules/bower/bin/bower install ! Push rejected, failed to compile Node.js app 

这是我的Bower.json

  { "name": "mean", "version": "1.0.0", "dependencies": { "bootstrap": "*", "angular": "*", "angular-resource": "*", "angular-cookies": "*", "angular-ui-utils": "*", "angular-bootstrap": "*", "json3": "*", "jquery": "*", "angular-ui-router": "*", "angular-animate": "*", "move.js": "git://github.com/visionmedia/move.js.git#~0.3.3", "animate.css": "*", "ngAnimate-animate.css": "*", "angularLocalStorage": "~0.1.7", "jquery-nicescroll": "*" }, "resolutions": { "angular": "1.2.4" } } 

这是我的Package.json

 "scripts": { "start": "node node_modules/grunt-cli/bin/grunt", "test": "node node_modules/grunt-cli/bin/grunt test", "postinstall": "./node_modules/bower/bin/bower install" }, 

我也遇到了这个错误。 每三分之一推Herku失败,因为凉亭postinstall。

虽然这不是一个强大的修复,我不完全明白为什么它有帮助! 但是这让我很沮丧,所以希望能帮助别人。

尽pipe/ lib文件夹被添加到.gitignore,但在部署heroku之前强制添加它

 git add -f public/lib git commit -m "force add bower libs" git push heroku master 

这可能与涉及这个问题有关,其原因目前仍在调查:

https://github.com/bower/bower/issues/933

我也遇到了一些类似的问题, bower install命令在heroku上失败。 以下是对我有用的东西:

1.暂时从.gitignore删除node_modulesbower_components

  • 这似乎修复了当尝试通过heroku中的后安装脚本使用bower安装Angular时ENOENT错误。
  • 注意:如果您在.bowerrc文件中指定了不同的安装目录,那么请确保该目录存在于.gitignore

2.编辑(或创build) .bowerrc并告诉它使用项目目录本地的临时目录:

 {
     “存储”:{
         “packages”:“.bower-cache”,
         “registry”:“.bower-registry”
     },
     “tmp”:“.bower-tmp”
 }
  • 默认情况下,bower试图在/app使用一个目录,导致ENOTEMPTY错误(也许是因为它试图清除这些目录,但是因为它们与其他用户共享,所以没有访问权限?只是抛出一个猜测…)
  • 使用项目本地的目录修复冲突。

希望这可以帮助别人。

注:即使执行上述步骤后, bower install命令仍可能偶尔会失败。 但是,它通常是第二次或第三次运行 – 只要再次运行命令…直到问题解决,这是我可以提供的最好的build议。

我遇到过同样的问题。 问题是在bower.json文件中:

 { "name": "mean", "version": "0.1.3", "dependencies": { "angular": "1.2.8", "angular-resource": "latest", "angular-cookies": "latest", "angular-mocks": "latest", "angular-route": "latest", "bootstrap": "3.0.3", "angular-bootstrap": "0.10.0", "angular-ui-utils": "0.1.0" } } 

“凉亭安装”无法确定angular度版本,需要手动干预才能select正确的版本:

 Unable to find a suitable version for angular, please choose one: 1) angular#1.2.8 which resolved to 1.2.8 and has mean as dependants 2) angular#1.2.9 which resolved to 1.2.9 and has angular-cookies#1.2.9, angular-mocks#1.2.9, angular-resource#1.2.9, angular-route#1.2.9 as dependants 3) angular#>= 1.0.2 which resolved to 1.2.10-build.2176+sha.e020916 and has angular-ui-utils#0.1.0 as dependants 4) angular#>=1 which resolved to 1.2.10-build.2176+sha.e020916 and has angular-bootstrap#0.10.0 as dependants Prefix the choice with ! to persist it to bower.json [?] Answer: 

所以Heroku在执行脚本时失败。

固定

只要在你的bower.json文件中改变angular度的版本bower.json

 "angular": "1.2.10", 

1.2.9也将起作用。

@ ac360这完全不是一个问题。 这通常是一个警告,如果不同的库使用相同的依赖关系,但使用不同的版本。 你永远不要把你的public/lib to the repo添加public/lib to the repo 。 这打败了什么可以用于凉亭的目的。 保持你的repo尽可能的轻,让依赖在bower.json时候下载和解决,这样你就可以在你的bower.json定义的参数中获得最新和最好的

为了彻底解决这个问题,对于自动部署,bower给了我们一个名为resolutionsbower.json属性

只需在您的bower.json创build以下bower.json

 "resolutions": { "ember": "1.2.10" } 

即使定义了解决scheme,仍然存在问题的原因是因为您select的版本不能满足所有依赖关系,所以在安装heroku时出现了这个问题。

或者,你可以在本地build立,当你被问到哪个版本可供select时,如果你select的号码是在爆炸之前! 象征,凉亭将更新您的bower.json为您!

请参阅: https : //github.com/bower/bower/issues/532

我通过使用下面的命令来确保在package.json中保存bower。 在尝试运行bower安装之前,保存将在服务器上使用npm安装bower

 npm install bower --save 

package.json中的postinstall脚本“postinstall:”bower install“之后在heroku上工作。