Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

2606 info postinstall [email protected]
2607 verbose unsafe-perm in lifecycle true
2608 info [email protected] Failed to exec postinstall script
2609 error [email protected] postinstall: `./node_modules/bower/bin/bower install`
2609 error Exit status 1
2610 error Failed at the [email protected] 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

Here is my 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"
  }
}

Here is my 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"
},
like image 852
ac360 Avatar asked Dec 29 '13 15:12

ac360


People also ask

How do you run npm install on Heroku?

Run the npm install command in your local app directory to install the dependencies that you declared in your package. json file. Start your app locally using the heroku local command, which is installed as part of the Heroku CLI. Your app should now be running on http://localhost:5000/.

Can Heroku use yarn?

Specifying a Yarn Version json , Heroku downloads and installs Yarn, which is used to install your dependencies. Specify the version you are using locally so that Heroku uses the same version.

Does Heroku support EJS?

ejs doesn't work on NodeJS app in Heroku.


2 Answers

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
like image 70
Yuri Avatar answered Nov 10 '22 05:11

Yuri


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.

like image 29
Sergey K Avatar answered Nov 10 '22 04:11

Sergey K