Github Actions 和 npm - npm:找不到命令

Ash*_*er2 3 ubuntu node.js npm nvm github-actions

我已经在 github actions 上创建了一个部署操作。这一切都适用于composer install 和 git pull master 分支。然而,在我的数字海洋水滴上,我遇到了问题: bash: line 4: npm: command not found 如果我 ssh 进入我的服务器,我可以很好地使用 npm。这是通过 nvm 安装的并使用最新版本,但由于某种原因无法通过操作访问。我的部署脚本是


on:
  push:
    branches: [master]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Deploy Laravel APP
        uses: appleboy/ssh-action@v0.1.4
        with:
          host: ${{secrets.SSH_HOST}} 
          key: ${{secrets.SSH_KEY}} 
          username: ${{ secrets.SSH_USER }} 

          script: |
            cd /var/www/admin
            git pull origin master
            composer install
            npm install
            npm run prod
Run Code Online (Sandbox Code Playgroud)

我认为这更多地与 nvm 的设置有关,因为我可以通过 ssh 使用它,但由于他们使用同一用户通过 ssh 登录,我似乎看不到问题。

有什么想法可以解决此问题以授予访问/允许 github 操作使用 npm 的权限吗?

Tai*_*uan 6

I had the same issue, and finally found the solution. I could solve the issue by adding the following lines before running npm commands.

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
Run Code Online (Sandbox Code Playgroud)

These commands helps the terminal fix the node path installed by nvm. Reference link is here.