Node.js Heroku Deployment - Fails To Exec Postinstall Script To Install Bower

后端 未结 5 826
暗喜
暗喜 2021-01-31 22:47

Deployment of my Node.js MEAN app to heroku fails with the following errors. I can\'t figure out what is wrong with the bower install...

Here is the error message:

相关标签:
5条回答
  • 2021-01-31 23:24

    This is likely related to this issue with bower, the cause of which is currently still being investigated:

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

    I've also been having some similar issues with the bower install command failing on heroku. Here's what worked for me:

    1. Temporarily remove node_modules and bower_components from .gitignore.

    • This seemed to fix an ENOENT error when trying to install Angular using bower through a postinstall script in heroku.
    • Note: If you specify a different installation directory for bower components in your .bowerrc file, then make sure that directory is not present in your .gitignore.

    2. Edit (or create) .bowerrc and tell it to use temp directories that are local to the project directory:

    {
        "storage": {
            "packages": ".bower-cache",
            "registry": ".bower-registry"
        },
        "tmp": ".bower-tmp"
    }
    
    • By default, bower was trying to use a directory in /app, which was resulting in ENOTEMPTY errors (maybe because it was trying to clear those directories, but it didn't have access because they are shared with other users? Just throwing out a guess...)
    • Using a directory that's local to the project fixed the conflicts.

    Hope this helps someone else.

    Note: Even after performing the above steps, the bower install command may still occasionally fail. However, it generally works the second or third time - just try running the command again... Until the underlying issue is resolved, that's the best advice that I can offer.

    0 讨论(0)
  • 2021-01-31 23:25

    @ac360 This isn't an issue with bower at all. It's generally a warning you can get if different libraries use the same dependency however a different version. You should never add your public/lib to the repo. That defeats the purpose of what bower can be used for. Keep your repo as light as possible, and let dependencies download and resolve at build time so you can get the latest and greatest within the parameters defined in your bower.json

    To resolve this issue completely for auto-deploys, bower gives us a property on the bower.json called resolutions

    Simply create the following in your bower.json

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

    The reason you still had problems even if you had resolutions defined was because the version you picked wasn't going to satisfy all dependencies so the question came up during the heroku install.

    Alternatively, you can build locally, and when you are asked which version to choose from, if you preceed the number choice with the bang ! symbol, bower will update your bower.json for you!

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

    0 讨论(0)
  • 2021-01-31 23:27

    I got it working by ensuring to save bower in package.json using the command below. The save will install bower using npm on server before attempting to run bower install

    npm install bower --save
    

    the postinstall script in package.json "postinstall:"bower install" worked on heroku after that.

    0 讨论(0)
  • 2021-01-31 23:36

    I get this error a lot too. every third push to heroku fails because of bower postinstall.

    While this is not a robust fix, and I don't fully understand why it helps! but this hepled me, so hopefully will help someone else.

    Despite /lib folder is being added to .gitignore, force add it before deploying heroku

    git add -f public/lib
    git commit -m "force add bower libs"
    git push heroku master
    
    0 讨论(0)
  • 2021-01-31 23:36

    I had the same issue. The problem was that in the bower.json file:

    {
        "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" is unable to determine the angular version and requires manual intervention to choose the right version:

    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: 
    

    So Heroku fails when it executes the script.

    FIX

    Just change the version of angular in your bower.json file:

    "angular": "1.2.10",
    

    1.2.9 will also work.

    0 讨论(0)
提交回复
热议问题