从 SSH 触发时找不到 Npx returns 命令

Npx returns command not found when triggered from SSH

我在 SO 上发现了很多类似的问题,但遗憾的是它们与我的问题无关。

我在 NVM 上安装了 Node。

$ node -v
v14.16.0

$ npm -v
7.7.6

$ npx -v
7.7.6

我正在编写一个部署脚本,它将 运行 git 从我们的存储库中提取,然后(除其他外)编译资产。如果这有帮助,工作环境是Laravel 8,但我认为这与我的问题无关。

运行 npm install && npm run prod 在远程服务器上以用户身份登录时将完美运行。但是 运行通过 SSH returns 执行相同的命令如下:

jaeger@local-computer~$ ssh deploy@distant-server-with-nvm-node-npm-npx '/bin/sh -c "node -v && npm -v && npx -v && exit"'


Connecting...
v14.16.0
7.7.6
/bin/sh: 1: npx: not found

所以...我迷路了。我已经看到关于节点 and/or npm 被识别的问题,但是 none 关于 npx 的问题,我需要它与 Laravel 混合。当然,运行来自远程服务的上述评论将完美工作。

我尝试了什么:

我还能尝试什么?提前谢谢你

很可能,nvm 已经安装在您的 .bashrc 中,但您正在触发另一个 shell (sh)。即使 /bin/sh 指向 bash,这也会禁用 rcfile - 请参阅下面的解释。直接用bash

请注意 bash 联机帮助页的摘录: --norc

Do not read and execute the system wide initialization file /etc/bash.bashrc and the personal initialization file ~/.bashrc if the shell is interactive. This option is on by default if the shell is invoked as sh.

这意味着您需要使用标志 -i, 除了通过 -c.

指定命令