Grunt failing during Capistrano deployment

I’m unsure of what my issue is here - wondering if anyone can point me in the right direction. I’m using a custom theme built on Roots, so I’m building assets on the server as part of the deployment.

I can deploy to a local server fine. However, when I’m deploying to a external server, I get most of the way through the deployment process (in the part where I’m building assets), and it fails.

I successfully run npm install (which also runs bower install), but when I get to my grunt build, I get:

/usr/bin/env:
node
: No such file or directory

This is the command that gets run:

/home/adam/bin/grunt --no-color --gruntfile ~/site/releases/20150227170835/content/themes/themename/Gruntfile.js build

However, if I ssh in to the server (with the same login that Capistrano uses) and run the command myself, it works fine.

Any ideas?

Capistrano uses a non-interactive PTY, meaning that just SSH’ing in as the same user isn’t the same thing as what Capistrano does when it runs a command.

Things like bash .profile or .bash_profile etc aren’t loaded. The weird thing with your problem is that npm install works. Anyway, here’s the general theory to fix problems like these which might in your case too:

  1. Run which node
  2. Note the path output
  3. Add the following to your deploy.rb:
SSHKit.config.command_map[:node] = "<path from above>"

Or, you can also modify the $PATH that Capistrano uses:

set :default_env, { path: "/usr/local/bin:$PATH" }

You can try putting the folder in there that contains node.