Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying to heroku with grunt, bower, node modules

I am deploying a mean app to heroku and am using bower and grunt. Should I include my node modules in the git repo? If not, I'm really not sure how I need to deploy because the post script references a bower install from the node modules. Should I include my bower_components in the git repo? It doesn't seem like I should because isn't the whole point of the postscript the execute the bower install on heroku? But when I do I get an error. Here are my bower dependencies:

"dependencies": {
    "angular": "1.2.x",
    "angular-mocks": "~1.2.x",
    "jquery": "1.10.2",
    "bootstrap": "~3.1.1",
    "angular-bootstrap" : "0.11.0"
  }

And my package.json

{
  "main": "server.js",
  "engines": {
    "node": "0.10.29"
  },
  "dependencies": {
    "express": "~3.4.x",
    "mongoose": "~3.6.x",
    "mongodb": "^1.4.0",
    "ejs": "*",
    "email-templates" : "1.0.0",
    "crypto": "0.0.3",
    "lodash": "~2.4.1",
    "aws-sdk": "2.0.0-rc11",
    "passport" : "~0.1.17",
    "passport-local" : "~0.1.6",
    "connect-flash" : "~0.1.1",
    "winston": "0.6.x",
    "gm"    : "1.16.0",
    "apn" : "1.5.2",
    "bcrypt-nodejs" : "latest",
    "angular-wizard": "latest",
    "point-in-polygon": "latest",
    "node-mailgun": "0.0.2",
    "nodemailer"  : "0.7.0",
    "passport-facebook" : "1.0.3"
  },
  "devDependencies": {
    "supertest": "0.5.x",
    "bower": "0.6.x",
    "mocha": "1.8.x",
    "should": "1.2.x",
    "karma": "~0.10",
    "protractor": "^0.24.2",
    "http-server": "^0.6.1",
    "bower": "^1.3.1",
    "grunt-cli": "~0.1.13",
    "grunt-env": "~0.4.1",
    "grunt-node-inspector": "~0.1.3",
    "grunt-contrib-watch": "~0.6.1",
    "grunt-contrib-jshint": "~0.10.0",
    "grunt-contrib-csslint": "^0.2.0",
    "grunt-contrib-uglify": "~0.4.0",
    "grunt-contrib-cssmin": "~0.9.0",
    "grunt-nodemon": "~0.2.0",
    "grunt-concurrent": "~0.5.0",
    "grunt-mocha-test": "~0.10.0",
    "grunt-karma": "~0.8.2",
    "grunt-protractor-runner": "~1.0.0",
    "load-grunt-tasks": "~0.4.0",
    "jasmine-reporters": "~0.4.0",
    "karma": "~0.12.0",
    "karma-jasmine": "~0.2.1",
    "karma-coverage": "~0.2.0",
    "karma-chrome-launcher": "~0.1.2",
    "karma-firefox-launcher": "~0.1.3",
    "karma-phantomjs-launcher": "~0.1.2",
    "karma-junit-reporter": "~0.2",
    "shelljs": "^0.2.6",
    "xunit-file": "*"
  },
  "scripts": {
    "postinstall": "node_modules/.bin/bower install",

    "pretest": "npm install",
    "test": "karma start test/karma.conf.js",
    "test-single-run": "karma start test/karma.conf.js  --single-run",

    "preupdate-webdriver": "npm install",
    "update-webdriver": "webdriver-manager update",

    "preprotractor": "npm run update-webdriver",
    "protractor": "protractor test/protractor-conf.js",

    "update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/, '//@@NG_LOADER_START@@\\n' + cat('bower_components/angular-loader/angular-loader.min.js') + '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\""
  }
}

I get this error:

   5816 info [email protected] Failed to exec install script
5817 error [email protected] install: `node-gyp rebuild`
5817 error Exit status 1
5818 error Failed at the [email protected] install script.
5818 error This is most likely a problem with the fsevents package,
5818 error not with npm itself.
5818 error Tell the author that this fails on your system:
5818 error     node-gyp rebuild
5818 error You can get their info via:
5818 error     npm owner ls fsevents
5818 error There is likely additional logging output above.
5819 error System Linux 3.8.11-ec2
5820 error command "/tmp/build_2cc32425-eae7-45af-8b95-104e1c2c7c53/vendor/node/bin/node" "/tmp/build_2cc32425-eae7-45af-8b95-104e1c2c7c53/vendor/node/bin/npm" "rebuild"
5821 error cwd /tmp/build_2cc32425-eae7-45af-8b95-104e1c2c7c53
5822 error node -v v0.10.29
5823 error npm -v 1.4.14
5824 error code ELIFECYCLE
5825 verbose exit [ 1, true ]

 !     Push rejected, failed to compile Node.js app

I have read that i need to npm install -g karma but that does not help. Or an error with the bower install... Are my dev dependencies incorrect?

like image 305
thebiglebowski11 Avatar asked Jul 02 '14 15:07

thebiglebowski11


2 Answers

I found this video tutorial from Joe Eames to be quite useful for developing with the MEAN stack and deploying to Heroku: http://pluralsight.com/training/courses/TableOfContents?courseName=building-angularjs-nodejs-apps-mean&highlight=

The guidance given is that you shouldn't include your node_modules in the git repo you should let Heroku build those for you when you deploy.

Reading through your files it seems that you perhaps have too many dependencies listed. i.e I don't think you need 'Bower' listed as a dev-dependency in package.json. Equally, the script you've included in your package.json is not something I've really seen before. I would deploy using either Heroku commands or the grunt build pack found here: github.com/mbuchetics/heroku-buildpack-nodejs-grunt.git

More description on how to deploy to Heroku using grunt can be found here: https://medium.com/@3runjo/how-to-deploy-a-grunt-project-on-heroku-c227cb1ddc56

I realise this isn't a full answer, but should give you enough leads to de-bug your problem.

like image 73
ChrisAddams Avatar answered Sep 16 '22 23:09

ChrisAddams


You are missing a nodejs buildpack for heroku. Also if you are using grunt as I see you need to go for a grunt nodejs buildpack. This is the one:

https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt

You just need to register in your Gruntfile.js the tasks for building in heroku like this for example:

grunt.registerTask('heroku:development', 'clean less mincss');
grunt.registerTask('heroku:production', 'clean less mincss uglify');

Also remember to add the config variable to heroku app:

heroku config:add BUILDPACK_URL=https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt.git

You are using a really old version of bower in the package.json, mine is:

"scripts": {
    "postinstall": "./node_modules/bower/bin/bower install"
},
"dependencies": {
    "bower": "^1.3.5",
like image 44
fernandopasik Avatar answered Sep 20 '22 23:09

fernandopasik