Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm command not found #21

Closed
yy921010 opened this issue Jan 4, 2020 · 17 comments
Closed

npm command not found #21

yy921010 opened this issue Jan 4, 2020 · 17 comments

Comments

@yy921010
Copy link

yy921010 commented Jan 4, 2020

I have npm installed on my server, why does the 'npm command not found' error during deployment?

@rieckpil
Copy link

rieckpil commented Jan 8, 2020

I encountered a similar problem where Maven (Java Build Tool) was not available within my SSH session but installed on the server:

 ======CMD======
cd /***/projects/xyz
git pull
mvn clean package

======END======
err: From https://github.com/xyz
err:    a6e1f0a..0efd9b7  master     -> origin/master
out: Updating a6e1f0a..0efd9b7
out: Fast-forward
out:  .github/workflows/maven.yml | 5 +++--
out:  1 file changed, 3 insertions(+), 2 deletions(-)
err: bash: line 2: mvn: command not found
2020/01/08 18:15:58 Process exited with status 127
##[error]Docker run failed with exit code 1

@SimonSun1988
Copy link

i have this error too.

@SimonSun1988
Copy link

@yy921010 try this, fixed my problem

script: |
  export NVM_DIR=~/.nvm
  source ~/.nvm/nvm.sh
  npm --help

@yy921010
Copy link
Author

@yy921010 try this, fixed my problem

script: |
  export NVM_DIR=~/.nvm
  source ~/.nvm/nvm.sh
  npm --help

thanks!!

@apardo04
Copy link

apardo04 commented Mar 31, 2020

@yy921010 try this, fixed my problem

script: |
  export NVM_DIR=~/.nvm
  source ~/.nvm/nvm.sh
  npm --help

Fixed it for me as well! Thank you. Do you know why this fixed the problem?

@SimonSun1988
Copy link

i think because docker not export environment

@nathanhannig
Copy link

Why is it not loading the users .bashrc correctly?

@fcbuz2000
Copy link

npm: command not found
Reason:
I use nvm for the server node environment, and nvm will not install the node environment in the /usr/local/bin/ directory, so that sudo can't find the corresponding instructions, and finally create a soft connection to solve

sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/node" "/usr/local/bin/node"
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/npm" "/usr/local/bin/npm"
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/pm2" "/usr/local/bin/pm2"

you can test "sudo npm -v"

https://blog.csdn.net/weixin_40599109/article/details/110825357

@vanyauhalin
Copy link

Why is it not loading the users .bashrc correctly?

@nathanhannig, maybe exec bash can help you (this solved my problem):

script: |
  exec bash
  pm2 reload app.js

@oshanz
Copy link

oshanz commented Jan 28, 2022

thanks for the information @vanyauhalin
to solve my issue I needed to do a minor change to your code. apparently, you need to get a login shell. so you can load all bash variables and configurations.

        script: |
          exec bash \-l
          cd ~/project-dir
          ./deploy.sh

it seems what "appleboy/ssh-action" underline do is a sh shell, not a bash shell. it's similar to

ssh a@b -t sh

@hyoretsu
Copy link

None of the above worked for me. exec bash worked but didn't run my command.

@stepanjakl
Copy link

Hello all, I have been facing the same issue. @oshanz pointed out well that when logging through the SSH, the shell is in an interactive mode instead of a login mode. So, some profile information and paths are not loaded. More on this issue here.

In any case, I managed to get it working with a here document syntax:

script: |
    bash -l -c "$(cat <<- EOF
    echo "This should work"
    EOF
    )"

There's just one issue, I keep getting this error err: bash: line 107: [: -ne: unary operator expected on some lines. Fortunately, it doesn't stop the script even with script_stop: true.

I think this might also be a (bit hacky) solution for #31.

@fpmanuel
Copy link

@yy921010 try this, fixed my problem

script: |
  export NVM_DIR=~/.nvm
  source ~/.nvm/nvm.sh
  npm --help

Fixed it for me as well! Thank you. Do you know why this fixed the problem?

This works for me too.

@dhrubkumar50
Copy link

dhrubkumar50 commented Apr 8, 2023

thanks for the information @vanyauhalin to solve my issue I needed to do a minor change to your code. apparently, you need to get a login shell. so you can load all bash variables and configurations.

        script: |
          exec bash \-l
          cd ~/project-dir
          ./deploy.sh

it seems what "appleboy/ssh-action" underline do is a sh shell, not a bash shell. it's similar to

ssh a@b -t sh

exec bash -l Adding this Help me Thanks you..😍😍😍

@goldthree-shit
Copy link

I encountered a similar problem where Maven (Java Build Tool) was not available within my SSH session but installed on the server:

 ======CMD======
cd /***/projects/xyz
git pull
mvn clean package

======END======
err: From https://github.com/xyz
err:    a6e1f0a..0efd9b7  master     -> origin/master
out: Updating a6e1f0a..0efd9b7
out: Fast-forward
out:  .github/workflows/maven.yml | 5 +++--
out:  1 file changed, 3 insertions(+), 2 deletions(-)
err: bash: line 2: mvn: command not found
2020/01/08 18:15:58 Process exited with status 127
##[error]Docker run failed with exit code 1

Hey,Gay , I encountered too. So how do you work out? Thank you

@sabuhiteymurov
Copy link

I encountered a similar problem where Maven (Java Build Tool) was not available within my SSH session but installed on the server:

 ======CMD======
cd /***/projects/xyz
git pull
mvn clean package

======END======
err: From https://github.com/xyz
err:    a6e1f0a..0efd9b7  master     -> origin/master
out: Updating a6e1f0a..0efd9b7
out: Fast-forward
out:  .github/workflows/maven.yml | 5 +++--
out:  1 file changed, 3 insertions(+), 2 deletions(-)
err: bash: line 2: mvn: command not found
2020/01/08 18:15:58 Process exited with status 127
##[error]Docker run failed with exit code 1

Hey,Gay , I encountered too. So how do you work out? Thank you

You have to export mvn path, try to use echo $PATH with ssh-action and on your actual server, compare the results.

@goldthree-shit
Copy link

Thank you, it is useful;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests