You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从Git安装node-mbus npm包失败的原因及解决方法

node-mbus从Git仓库安装失败的解决方法

问题现象

  • 在package.json中指定npm版本号时可正常安装:
    ...
    "dependencies": {
      "node-mbus": "^2.0.0"
    }
    ...
    
  • 改为直接使用Git仓库地址后,安装报错:
    ...
    "dependencies": {
      "node-mbus": "https://github.com/Apollon77/node-mbus"
    }
    ...
    
    错误信息:
    npm ERR! make: *** No rule to make target 'Release/obj.target/libmbus/libmbus/mbus/mbus-protocol-aux.o', needed by 'Release/obj.target/mbus.a'.  Stop.
    
  • 其他包(如xml2js)无论指定版本还是Git地址都能正常安装,排除依赖地址本身的问题。

排查过程

  • 克隆node-mbus仓库到本地后,执行npm i file:<本地克隆路径>可正常完成安装;
  • 使用npm i --ignore-scripts https://github.com/Apollon77/node-mbus跳过脚本安装后,手动执行node-gyp configure; node-gyp build也能成功编译。

问题原因与解决方案

原脚本配置问题

node-mbus原package.json中的scripts配置如下:

...
"scripts": {
  "prepare": "rm -rf libmbus && git clone -b build-windows --single-branch https://github.com/Apollon77/libmbus.git libmbus && rm libmbus/.gitignore && cp config.h libmbus/config.h",
  "install": "node-gyp rebuild",
  "test": "nyc --reporter=lcov node_modules/mocha/bin/mocha --exit",
  "release": "release-script"
},
...

当从Git仓库安装包时,npm的脚本执行顺序导致prepare脚本在编译步骤之后才执行,此时libmbus依赖还未被拉取,进而引发编译错误。

修改方案

将prepare脚本改为preinstall,确保在install脚本(执行node-gyp rebuild)之前完成libmbus的拉取与配置:

...
"scripts": {
  "preinstall": "rm -rf libmbus && git clone -b build-windows --single-branch https://github.com/Apollon77/libmbus.git libmbus && rm libmbus/.gitignore && cp config.h libmbus/config.h",
  "install": "node-gyp rebuild",
  "test": "nyc --reporter=lcov node_modules/mocha/bin/mocha --exit",
  "release": "release-script"
},
...

修改后重新执行安装即可正常完成。

内容的提问来源于stack exchange,提问作者Shorosky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 18:50:22