Skip to content

打开npm直接报错Api invoke error Error invoking remote method 'apiInvoke': Error: /bin/sh: npm: command not found #427

Open

Description

@ammondu
  • 你是否在现有 Issue列表 中搜索过相同问题,但未找到?

Ⅰ. 请说明操作系统及DS的版本号:

  1. 操作系统:macos 14.7.2
  2. DS版本号:2.0.0-RC1

Ⅱ. 问题描述:

打开npm 直接报错 Api invoke error
Error invoking remote method 'apiInvoke': Error: /bin/sh: npm: command not found

Ⅲ. 期望的结果:

解决bug

Ⅳ. 如何复现问题?

直接打开npm就会提示。

Ⅴ. 请提供相关的错误日志,尽可能的详细:(日志文件在 ${user.home}/.dev-sidecar/logs/ 目录下)

[2025-01-02T10:49:06.864] [INFO] core - shell: npm config list --json
commands: npm config list --json 
   error: Error: Command failed: npm config list --json
/bin/sh: npm: command not found
  cmd: 'npm config list --json'

Activity

  1. wangliang181230 commented on Jan 2, 2025

    @wangliang181230
    Collaborator

    看下环境变量有没有配置吧。

  2. added
    Waiting for a reply/降级保留issue/inactive对于open issue,是等待用户于3天内回复的问题,无回复将被关闭;对于closed issue,这是代表问题虽然因不活跃而关闭,但仅仅是被降级,仍然允许回复并可以视情况再次打开
    on Jan 3, 2025
  3. Ericlyclyclyc commented on Jan 4, 2025

    @Ericlyclyclyc

    me too...
    什么鬼: Api invoke error Error invoking remote method 'apiInvoke': Error: 'npm' �����ڲ����ⲿ���Ҳ���ǿ����еij��� ���������ļ���

  4. Ericlyclyclyc commented on Jan 4, 2025

    @Ericlyclyclyc

    cmd打开npm正常啊

    看下环境变量有没有配置吧。

  5. lanhao945 commented on Jan 6, 2025

    @lanhao945

    遇到了类似的问题。

    在ubuntu 22.04 下, node 和npm 均以安装好(通过nvm安装),且终端中node -v 和 npm -v 均能正确输出版本信息。

    终端和dev-sidecar 以相同用户启动。

    当dev-sidecar 选中npm 代理时,输出异常“Api invoke error Error invoking remote method 'apiInvoke': Error: /bin/bash: 行 1: npm: 未找到命令”

  6. wangliang181230 commented on Jan 6, 2025

    @wangliang181230
    Collaborator

    估计是权限问题,你们把ds的权限提高一下试试。

  7. ammondu commented on Jan 6, 2025

    @ammondu
    Author
    image
  8. wangliang181230 commented on Jan 6, 2025

    @wangliang181230
    Collaborator

    你们尝试下把npm的完整路径配置到 ds 的 npm命令里试一下?

  9. wangliang181230 commented on Jan 6, 2025

    @wangliang181230
    Collaborator

    如:
    图片

  10. ammondu commented on Jan 6, 2025

    @ammondu
    Author

    我mac下确实没有这个 /bin/sh: npm: command not found

  11. ammondu commented on Jan 6, 2025

    @ammondu
    Author

    我在我mac中brew install npm 问题解决。你们可以继续讨论。

  12. lanhao945 commented on Jan 6, 2025

    @lanhao945

    通过查找npm 路径得到:

    home/username/.nvm/versions/node/v23.5.0/bin/npm
    然后按照要求,在devsidecar中配置npm 路径,重启后,尝试开启npm 代理:
    Error invoking remote method 'apiInvoke': Error: /usr/bin/env: "node": 没有那个文件或目录

    从表现来看,不像是权限,更像是,devsidecar中将node 的路径(或者npm路径)写得相对固定?

  13. lanhao945 commented on Jan 6, 2025

    @lanhao945

    这是devsidecar core.log 中关于node 的部分日志:

    ===>
    commands: npm config set proxy=http://127.0.0.1:31181 
       error: Error: Command failed: npm config set proxy=http://127.0.0.1:31181
    /bin/bash: 行 1: npm: 未找到命令
    
        at ChildProcess.exithandler (node:child_process:408:12)
        at ChildProcess.emit (node:events:526:28)
        at maybeClose (node:internal/child_process:1092:16)
        at Socket.<anonymous> (node:internal/child_process:451:11)
        at Socket.emit (node:events:526:28)
        at Pipe.<anonymous> (node:net:687:12) {
      killed: false,
      code: 127,
      signal: null,
      cmd: 'npm config set proxy=http://127.0.0.1:31181'
    } 
    <===
    
  14. lanhao945 commented on Jan 6, 2025

    @lanhao945

    我在我mac中brew install npm 问题解决。你们可以继续讨论。

    ubuntu中通过apt install 应该能解决这个问题。但是这里主要是用到了nvm,是希望通过nvm 来控制node 的版本。估计是引入了nvm 导致了逻辑不兼容。

  15. 9 remaining items

  16. Ericlyclyclyc commented on Jan 23, 2025

    @Ericlyclyclyc

    然后,发现关闭代理(点圆型按钮)在点开(也是点圆形按钮)就会自动打开了

  17. added
    seem a problem很有可能但不太确定的问题,值得继续讨论
    and removed
    seem a problem很有可能但不太确定的问题,值得继续讨论
    on Nov 28, 2025
  18. sdqdyzz commented on Apr 14, 2026

    @sdqdyzz
  19. cute-omega commented on Aug 18, 2026

    @cute-omega
    Collaborator

    如果确实遇到该问题,请在npm设置里写入你要调整的npm的完整路径

  20. removed
    seem a problem很有可能但不太确定的问题,值得继续讨论
    Todo待办事项
    on Aug 18, 2026
  21. RepublicGlory commented on Aug 22, 2026

    @RepublicGlory
    针对 npm 加速失败的问题(尤其是通过 nvm 在用户级安装 Node.js 的用户),可以在软件“NPM加速”界面中,将“npm命令名”修改为source ~/.bashrc && npm(若使用 Zsh,则改为 source ~/.zshrc && npm)
    
    有人建议直接填写 npm 的绝对路径,但测试发现会因找不到 node 而报错,因此推荐上述加载配置文件的方式。其原理是 dev-sidecar 执行 npm 时未自动加载用户的 shell 配置文件(如 ~/.bashrc),导致 nvm 设置的 PATH 未生效。对于非 nvm 用户,此问题可能不相关,但也可以尝试此方法。
    
    For users experiencing npm acceleration failures (especially those who installed Node.js via nvm in user space), you can fix it by going to the "NPM Acceleration" settings in the software and changing the "npm command" field to:source ~/.bashrc && npm“(If you use Zsh, use source ~/.zshrc && npm instead.)
    Some suggest using the absolute path to npm, but tests show that this leads to node: No such file or directory errors. So the above approach (loading the shell config file) is recommended. The reason is that dev-sidecar does not automatically load your shell configuration files (like ~/.bashrc) when executing npm, so the PATH set by nvm is not available. For non‑nvm users, this may not be the cause of the error, but you can still give it a try.
    
  22. RepublicGlory commented on Aug 22, 2026

    @RepublicGlory

    希望作者直接将nvm相应配置中直接加入 source ~/.bashrc 等相应指令,有助于新人直接使用,若还未添加,可以看前一个回复,有解决方法。

  23. lrx012 commented on Oct 18, 2026

    @lrx012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions