【问题标题】:Node.js Heroku Deployment - Fails To Exec Postinstall Script To Install BowerNode.js Heroku 部署 - 无法执行安装后脚本来安装 Bower
【发布时间】:2014-01-16 13:46:06
【问题描述】:

将我的 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"
},

【问题讨论】:

  • 现在您无需指定到 bower 所在的路径。这就足够了:“postinstall”:“bower install”

标签: javascript node.js heroku bower


【解决方案1】:

我通过确保使用以下命令将 bower 保存在 package.json 中来使其正常工作。在尝试运行 bower install 之前,保存将在服务器上使用 npm 安装 bower

npm install bower --save

package.json 中的安装后脚本 "postinstall:"bower install" 之后在 heroku 上工作。

【讨论】:

  • 这是恰当的解决方案
  • 是的。像魅力一样工作
【解决方案2】:

@ac360 这根本不是 bower 的问题。如果不同的库使用相同的依赖项但版本不同,通常会收到警告。你永远不应该添加你的public/lib to the repo。这违背了凉亭的用途。尽可能保持你的 repo 简洁,并让依赖项在构建时下载和解析,这样你就可以在 bower.json 中定义的参数范围内获得最新和最好的。

为了彻底解决自动部署的这个问题,bower 在bower.json 上为我们提供了一个名为resolutions 的属性

只需在您的 bower.json 中创建以下内容

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

即使您定义了解决方案,您仍然遇到问题的原因是因为您选择的版本不能满足所有依赖项,所以问题出现在 heroku 安装期间。

或者,您可以在本地构建,当系统询问您要选择哪个版本时,如果您在数字选择之前加上 bang ! 符号,bower 将为您更新 bower.json!

见:https://github.com/bower/bower/issues/532

【讨论】:

    【解决方案3】:

    我有同样的问题。问题是在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"
        }
    }
    

    “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: 
    

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

    修复

    只需更改 bower.json 文件中的 angular 版本即可:

    "angular": "1.2.10",
    

    1.2.9 也可以。

    【讨论】:

    • 现在这似乎是有道理的。 Heroku 可能无法理解这些附加信息。我今天试试这个!谢谢ibeitia :)
    【解决方案4】:

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

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

    bower install 命令在 heroku 上失败时,我也遇到了一些类似的问题。这对我有用:

    1.暂时从.gitignore 中删除node_modulesbower_components

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

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

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

    希望这对其他人有所帮助。

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

    【讨论】:

    • 将 Bower 的缓存/临时文件夹添加到 .gitignore 文件为我解决了 ENOTEMPTY 问题。
    【解决方案5】:

    我也经常遇到这个错误。由于 bower postinstall,每三次推送到 heroku 都会失败。

    虽然这不是一个强大的修复程序,但我不完全理解它为什么会有所帮助!但这对我有帮助,所以希望能帮助其他人。

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

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

    【讨论】:

    • @JimHall 这是我告诉 bower 安装所有库的目录
    • 这行得通,但它闻起来像黑客。谁能提供一些细节? @ibeitia 的回答对我不起作用。
    • 成功了,但到底到底发生了什么?
    • 所以,也许我可以阐明这一点。除了让安装后失败然后使用 Bower 依赖项的签入(scm)版本之外,这并没有做任何事情。这不是在 prod 设置上使用 bower。这甚至不是真正的 hack,它是对 bower/heroku/build 应该如何工作的公然滥用
    • ''npm install bower --save" 将是解决方案。使用 npm 安装 bower 将先安装 bower,然后再安装 bower 依赖项(没有任何问题)。添加所有 bower 安装的库不是我认为这是一种很好的做法。上述修复之所以有效,是因为 Bower 安装的库被强制推送到 heroku @reergymerej
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 2019-04-21
    • 2016-09-05
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多