Hyperledger区块链浏览器执行npm run start时遇语法错误求助
解决Hyperledger Explorer启动时
start.sh: Syntax error: "(" unexpected错误 问题场景
在生产网络中部署Hyperledger Explorer,执行npm start时触发如下错误:
************************************************************************************ **************************** Hyperledger Explorer ********************************** ************************************************************************************ ./start.sh: 24: Syntax error: "(" unexpected npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! hyperledger-explorer@1.1.8 app-start: `./start.sh` npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the hyperledger-explorer@1.1.8 app-start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /home/conqueror/.npm/_logs/2022-10-05T02_01_23_907Z-debug.log ERROR: "app-start" exited with 2. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! hyperledger-explorer@1.1.8 start: `run-s build app-start` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the hyperledger-explorer@1.1.8 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /home/conqueror/.npm/_logs/2022-10-05T02_01_23_940Z-debug.log
解决方法
该错误核心原因是start.sh使用了Bash专属语法(如数组、特定括号写法),但执行脚本时调用了不支持这些语法的Shell解释器(比如Debian/Ubuntu系统默认/bin/sh是Dash的软链接)。以下是几种可行的修复方案:
方案1:修正start.sh的Shebang行
- 打开blockchain-explorer目录下的
start.sh文件 - 检查第一行是否为
#!/bin/bash,如果是#!/bin/sh,修改为#!/bin/bash - 保存文件后,重新执行
npm start
方案2:修改package.json中的启动脚本
- 打开
package.json文件,找到scripts字段下的app-start项 - 将原内容
./start.sh修改为bash start.sh - 保存文件后,重新执行
npm start
方案3:直接用Bash执行脚本
跳过npm的脚本调用,直接在终端执行:
bash start.sh
方案4:调整系统默认Shell(生产环境需谨慎)
如果系统默认Shell不是Bash,可临时切换:
sudo ln -sf /bin/bash /bin/sh
注意:此操作会修改系统全局默认Shell,可能影响其他依赖
/bin/sh的脚本,生产环境操作前需充分评估风险。
内容的提问来源于stack exchange,提问作者Conqueror135
相关产品推荐
相关产品推荐

