Node.js Heroku部署 - 无法执行Postinstall脚本安装Bower

ac3*_*360 10 javascript heroku node.js 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
Run Code Online (Sandbox Code Playgroud)

这是我的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"
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我的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"
},
Run Code Online (Sandbox Code Playgroud)

Yur*_*uri 12

我也得到了这个错误.由于bower postinstall,每三次推送到heroku失败.

虽然这不是一个强大的修复,我不完全理解为什么它有帮助!但这使我感到困扰,所以希望能帮助别人.

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

git add -f public/lib
git commit -m "force add bower libs"
git push heroku master
Run Code Online (Sandbox Code Playgroud)


Ser*_*y K 12

这可能与凉亭的这个问题有关,其原因目前仍在调查中:

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

我也遇到过类似问题,bower install命令在heroku上失败了.这对我有用:

1.暂时删除node_modulesbower_components.gitignore.

  • ENOENT当尝试使用bower通过heroku中的postinstall脚本安装Angular时,这似乎修复了一个错误.
  • 注:如果您在指定的凉亭的部件不同的安装目录.bowerrc文件,然后确保目录是存在的.gitignore.

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

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

希望这有助于其他人.

注意:即使执行上述步骤,bower install命令仍可能偶尔失败.但是,它通常可以在第二次或第三次运行 - 只需再次尝试运行命令......直到底层问题得到解决,这是我能提供的最佳建议.


Iñi*_*tia 6

我遇到过同样的问题.问题是在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"
    }
}
Run Code Online (Sandbox Code Playgroud)

"bower install"无法确定角度版本,需要手动干预才能选择正确的版本:

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: 
Run Code Online (Sandbox Code Playgroud)

因此Heroku在执行脚本时失败了.

固定

只需更改bower.json文件中的角度版本:

"angular": "1.2.10",
Run Code Online (Sandbox Code Playgroud)

1.2.9 也会工作.