Npm fails in roots directory

Hi there,

I’m having some trouble setting up Bedrock/Roots.

cap staging deploy:check produces no errors.
cap staging deploy errors with:

INFO[1e36fc10] Running /usr/bin/env composer install --no-dev --prefer-dist --no-interaction --quiet --optimize-autoloader on wolfzeit.net
DEBUG[1e36fc10] Command: cd /home/jibazee/public_html/wolfzeit.com/releases/20141005175656 && ( WP_ENV=staging /usr/bin/env composer install --no-dev --prefer-dist --no-interaction --quiet --optimize-autoloader )
INFO[1e36fc10] Finished in 0.371 seconds with exit status 0 (successful).
DEBUG[e7a03498] Running /usr/bin/env if test ! -d /home/jibazee/public_html/wolfzeit.com/current/web/app/themes/wolfzeit; then echo “Directory does not exist ‘/home/jibazee/public_html/wolfzeit.com/current/web/app/themes/wolfzeit’” 1>&2; false; fi on wolfzeit.net
DEBUG[e7a03498] Command: if test ! -d /home/jibazee/public_html/wolfzeit.com/current/web/app/themes/wolfzeit; then echo “Directory does not exist ‘/home/jibazee/public_html/wolfzeit.com/current/web/app/themes/wolfzeit’” 1>&2; false; fi
DEBUG[e7a03498] Finished in 0.089 seconds with exit status 0 (successful).
INFO[5f8f8d5f] Running /usr/bin/env npm install --production --silent on wolfzeit.net
DEBUG[5f8f8d5f] Command: cd /home/jibazee/public_html/wolfzeit.com/current/web/app/themes/wolfzeit && ( WP_ENV=staging /usr/bin/env npm install --production --silent )
DEBUG[5f8f8d5f]
DEBUG[5f8f8d5f] module.js:340
DEBUG[5f8f8d5f] throw err;
DEBUG[5f8f8d5f] ^
DEBUG[5f8f8d5f] Error: Cannot find module ‘/home/jibazee/public_html/wolfzeit.com/releases/20141005175445/web/app/themes/wolfzeit/node_modules/bower/bin/bower’
DEBUG[5f8f8d5f] at Function.Module._resolveFilename (module.js:338:15)
DEBUG[5f8f8d5f] at Function.Module._load (module.js:280:25)
DEBUG[5f8f8d5f] at Function.Module.runMain (module.js:497:10)
DEBUG[5f8f8d5f] at startup (node.js:119:16)
DEBUG[5f8f8d5f] at node.js:906:3
cap aborted!
SSHKit::runner::ExecuteError: Exception while executing on host wolfzeit.net: npm exit status: 1
npm stdout: Nothing written
npm stderr: Nothing written
/Library/Ruby/Gems/2.0.0/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in exit_status=' /Library/Ruby/Gems/2.0.0/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:in block (5 levels) in _execute’
/Library/Ruby/Gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in call' /Library/Ruby/Gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in do_request’
/Library/Ruby/Gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:561:in channel_request' /Library/Ruby/Gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in dispatch_incoming_packets’
/Library/Ruby/Gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess’
etc…

Any help greatly appreciated.
Gabriel

What happens when you visit the failed release directory and run composer install?

Looks to be /home/jibazee/public_html/wolfzeit.com/releases/20141005175656

He tells me to composer update.

jibazee@s17263607:~/public_html/wolfzeit.com/releases/20141005181639]$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Nothing to install or update
Generating autoload files

I did this. Then I did composer install again. That went ok.
The deploy still has the same error.

Have you committed and pushed your latest project changes to your Git repo?

Yes. The local repository and bitbucket is in sync.
By the way, wpcli:db:push works. The local WordPress on MAMP looks fine in browser and even the half completed release on the server is reachable. Just the deploy doesn’t want…

In your local environment please delete your composer.lock file and re-run composer install. Then commit and push to your Git repo again and try another deployment.

Same thing :confused:
Maybe the error is located somewhere near the npm task?

The problem is the npm capistrano gem uses npm install --production by default which doesn’t install the devDependencies. Roots’ package.json has everything under devDependencies. See https://github.com/roots/roots/blob/master/package.json#L25 so nothing is actually being installed.

Add set :npm_flags, '--silent' to your config/deploy.rb and you’ll be good.

Thank you. This leads me one step further, but an error remains.

INFO[86ee4857] Running /usr/bin/env npm install --silent on wolfzeit.net
DEBUG[86ee4857] Command: cd /home/jibazee/public_html/wolfzeit.com/current/web/app/themes/wolfzeit && ( WP_ENV=staging /usr/bin/env npm install --silent )
DEBUG[86ee4857]     -[0G
DEBUG[86ee4857]     \[0G
DEBUG[86ee4857]     |[0G
.
.
.
DEBUG[86ee4857]     \[0G
DEBUG[86ee4857]     |[0G
DEBUG[86ee4857]     -[0G
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host wolfzeit.net: npm exit status: 3
npm stdout: Nothing written
npm stderr: Nothing written
/Library/Ruby/Gems/2.0.0/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='
/Library/Ruby/Gems/2.0.0/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:in `block (5 levels) in _execute'
/Library/Ruby/Gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `call'

First step to debugging Capistrano is to always run the command it failed on manually (as the same user you deploy as).

So manually run cd /home/jibazee/public_html/wolfzeit.com/current/web/app/themes/wolfzeit && ( WP_ENV=staging /usr/bin/env npm install --silent ) and see what’s going on.

It’s usually not an actual Capistrano error but an error with a command its running.

Are you able to SSH to your production environment without being prompted for credentials?

Can you perform tasks over SSH such as git push/pull without being prompted?

Yes, I can SSH without being prompted. I SSH via SSH keys.
I tried at the server to clone the bitbucket repo in a new directory,
then I’m prompted. Is it clever to put the private keys on the server?
Is SSH forward agent being used in every standard capistrano deploy?

My config is:

Sorry, that I bother you with these problems. I’m completely new to Capistrano and Roots. I could go my old way and deploy with SFTP but that’s so old fashioned…

I got further. The problem with npm was, that the owner of some gems on the server in ~/.npm was root. I changed all to my user and npm went ok. Then followed Bower && grunt, both went ok. Then npm comes again and wants to find a package.json in the root of the current release which doesn’t exist. Not locally neither on the server. Should there be one?

[420db568] Command: if test ! -d /home/jibazee/public_html/wolfzeit.com/releases/20141006180813; then echo "Directory does not exist '/home/jibazee/public_html/wolfzeit.com/releases/20141006180813'" 1>&2; false; fi
DEBUG[420db568] Finished in 0.090 seconds with exit status 0 (successful).
INFO[e7cff70a] Running /usr/bin/env npm install on wolfzeit.net
DEBUG[e7cff70a] Command: cd /home/jibazee/public_html/wolfzeit.com/releases/20141006180813 && ( WP_ENV=staging /usr/bin/env npm install )
DEBUG[e7cff70a]     [37m[40mnpm[0m [0m[31m[40mERR![0m [0m[35m
DEBUG[e7cff70a]     install[0m Couldn't read dependencies
DEBUG[e7cff70a]     [0m
DEBUG[e7cff70a]     [37m[40mnpm[0m [0m[31m[40mERR![0m [0m[35mpackage.json[0m ENOENT, open '/home/jibazee/public_html/wolfzeit.com/releases/20141006180813/package.json'
DEBUG[e7cff70a]     [0m[37m[40mnpm[0m [0m[31m[40mERR![0m
DEBUG[e7cff70a]     [0m[35mpackage.json[0m This is most likely not a problem with npm itself.
DEBUG[e7cff70a]     [0m[37m[40mnpm[0m [0m[31m[40mERR![0m [0m[35mpackage.json[0m npm can't find a package.json file in your current directory.

What happens when you cd into /home/jibazee/public_html/wolfzeit.com/releases/20141006180813 and run npm install?

The following happens:

jibazee@s17263607:~/public_html/wolfzeit.com/releases/20141006180813]$ npm install
npm ERR! install Couldn't read dependencies
npm ERR! package.json ENOENT, open '/home/jibazee/public_html/wolfzeit.com/releases/20141006180813/package.json'
npm ERR! package.json This is most likely not a problem with npm itself.
npm ERR! package.json npm can't find a package.json file in your current directory.

npm ERR! System Linux 3.13.0-042stab092.2
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install"
npm ERR! cwd /home/jibazee/public_html/wolfzeit.com/releases/20141006180813
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! path /home/jibazee/public_html/wolfzeit.com/releases/20141006180813/package.json
npm ERR! code ENOPACKAGEJSON
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/jibazee/public_html/wolfzeit.com/releases/20141006180813/npm-debug.log
npm ERR! not ok code 0

So your package.json is either missing or contains an error.

At which step of installation/deploy is the package.json generated or must be added to the root of the Bedrock directory? What should it content? I read the documentation, but found nothing about it.

A better question is why Capistrano is running npm install in the first place.

The npm Capistrano gem runs automatically on deploy:updated when you require it. You properly configured it by setting set :npm_target_path, fetch(:theme_path).

The problem is in your config/deploy.rb where you run execute 'npm', 'install' within the release_path. That’s the error you’re seeing because it obviously doesn’t exist there. Since you already have capistrano-grunt you don’t need that Grunt custom task at all.

I’ve updated your config here: https://gist.github.com/swalkinshaw/124481c40a26c21c0047

You didn’t post your Capfile but I’m assuming you’re requiring both the npm and Grunt gems.

2 Likes

Thank you so much. It works! (I had to correct two lines:)

set :theme_path, -> { "#{fetch(:release_path)}/web/app/themes/wolfzeit" }

to

set :theme_path, -> { "#{release_path}/web/app/themes/wolfzeit" }

and

set :grunt_tasks, 'deploy'

to

set :grunt_tasks, 'build'

Maybe this is not the correct way of using Grunt, but I’m new to Grunt and I have to learn.
“Das war eine schwere Geburt” is a german saying which means it wasn’t easy. It took me three weeks to setup Capistrano/Roots. :slight_smile:

One last question. If you know, where the .env lyes in the shared folder, you can read the data from outside. If I restrict the rights wordpress doesn’t work at all. Is this a security hole or have I misconfigured something?

Thanks again cfx and skalkinshaw for your professional and kind help!
Gabriel from Berlin