deployer icon indicating copy to clipboard operation
deployer copied to clipboard

'which npm' inconsistent between dep ssh and dep deploy

Open memen45 opened this issue 3 years ago • 5 comments
trafficstars

Using a simple recipe to test node deployment, I cannot get a simple npm install to work. I have installed node through nvm for the deployer user. I tested direct ssh, dep ssh and dep deploy, and only for dep deploy the which npm is different and which node cannot be found:

  • ssh which npm: /home/deployer/.nvm/versions/node/v18.10.0/bin/npm
  • dep ssh which npm: /home/deployer/.nvm/versions/node/v18.10.0/bin/npm
  • dep deploy which npm: /usr/local/bin/npm (incorrect) During deploy I get an error that /usr/bin/env 'node': No such file or directory, but I do not understand why the npm and node versions are not found.
namespace Deployer;

require 'recipe/common.php';

// Config

set('repository', '[email protected]:user/project.git');

add('shared_files', []);
add('shared_dirs', []);
add('writable_dirs', []);

// Hosts

host('server')
    ->set('remote_user', 'deployer')
    ->set('deploy_path', '/var/www/project-stage');

// Hooks

after('deploy:failed', 'deploy:unlock');

// build step
task('build', function () {
    run('which npm', real_time_output: true)
}
after('deploy:update_code', 'build');
  • Deployer version: 7.0.2
  • Deployment OS: ubuntu 22.04 LTS

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

memen45 avatar Sep 30 '22 18:09 memen45

This is due to differences b/w loging/interactive shells.

Just include nvm in rc file for dep deploy. Will write a small doc

antonmedv avatar Oct 01 '22 16:10 antonmedv

Thanks! Learned something today.

Solved it by appending the nvm lines from ~/.bashrc to ~/.profile:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

memen45 avatar Oct 03 '22 13:10 memen45

This is what I added to my task():

run('source ~/.nvm/nvm.sh && nvm use 20 && cd {{deploy_path}}/{{client_dir}}/current && yarn install');

With each "run" command, the node version has to be set like this, since each command runs in a new shell? Would recommend updating the ~/.profile

hnccox-yard avatar Apr 09 '24 08:04 hnccox-yard

I faced the same issue today. My unix knowledge is a bit limited so i will go with the easy way by copying the few lines into ~/.profile.

But we may be able to apply a fix in deployer recipe, we may be able to load the nvm file just before running the which command if I understand properly the workaround given in this thread: https://github.com/nvm-sh/nvm/issues/1290#issuecomment-280605971

Seb33300 avatar Apr 25 '24 02:04 Seb33300

Just leaving this here for those googling the problem.

I use nvs and I also had node working correctly through the console, but calling the "dep deploy" command returned an error for calling "which npm".

I took the advice from this comment and copied the lines from ~/.bashrc to ~/.profile. The command worked immediately.

export NVS_HOME="$HOME/.nvs"
[ -s "/opt/nvs/nvs.sh" ] && . "/opt/nvs/nvs.sh"

andrey-helldar avatar Jul 04 '24 10:07 andrey-helldar