Question

I want to run a node.js application on elastic beanstalk. I have a client which gets build by a grunt job (jade, less, concat, etc.) I excluded this folder from git

I can localy run this by grunt buildClient which is executed by grunt-cli

I added grunt and grunt-cli in my packages dev-dependencies

I want to run the grunt build before the application is launched, i already setup a configuration in .ebextensions/app.config

container_commands:
  01_build_client:
    command: grunt buildClient

I guess my cwd is /tmp/deployment/application/

but there is says Fatal error: Unable to find local grunt. I guess grunt-cli is installed, but why is this error?

i also tried putting the grunt job in the postinstall section of package.json, but this doesnt work as well.

How do i build my grunt job on a EBS instance?

Was it helpful?

Solution

When running Grunt on a paas, it's best to install a local copy of grunt-cli and grunt locally in the project. That way it's always available and is the exact version you'll need. Then you run npm install instead of grunt so your postinstall works properly.

For example, your package.json might look like this:

"grunt": "0.4.5",
"grunt-cli": "0.1.13",

OTHER TIPS

You can first specify the path to your gruntfile using the --gruntfile <pathToGruntfile> option on the grunt command. However, you'll also need to npm install grunt before running this, or you'll receive the same error.

I've just run into a similar problem whilst trying to get webpack bundilng on elastic beanstalk. I found that when elastic beanstalk runs an npm install it includes the --production flag. This means that you'll need to move your dev dependencies into the dependencies block.

Something else that caught me out is that eb doesn't seem to run the postinstall script which is really annoying! I did find that it runs the prestart script though.

My package.json file ended up looking something like this:

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "prestart": "node node_modules/webpack/bin/webpack.js"
  },
  "dependencies": {
    "backbone": "^1.2.1",
    "backbone.marionette": "^2.4.1",
    "webpack": "^1.9.10",
    ...
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top