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

执行rebar3触发escript异常:undefined function rebar3:main/1求助

解决rebar3执行时触发escript: exception error: undefined function rebar3:main/1异常

环境信息

  • Ubuntu 20.04.6 LTS
  • Erlang/OTP 22 [erts-10.6.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
  • Elixir 1.9.1 (compiled with Erlang/OTP 22)

异常信息

escript: exception error: undefined function rebar3:main/1
in function  escript:run/2 (escript.erl, line 758)
in call from escript:start/1 (escript.erl, line 277)
in call from init:start_em/1 
in call from init:do_boot/3

排查与解决步骤

该异常通常由rebar3脚本损坏、安装不完整或Erlang版本兼容性问题导致,可按以下步骤处理:

1. 重新安装rebar3

先移除现有可能损坏的rebar3文件:

rm -f ~/.local/bin/rebar3

重新下载并安装官方稳定版本:

curl -O https://s3.amazonaws.com/rebar3/rebar3
chmod +x rebar3
mv rebar3 ~/.local/bin/

验证安装结果:

rebar3 --version

2. 匹配Erlang版本兼容性

Erlang/OTP 22需搭配rebar3 3.14.x及以上版本。若重新安装后仍报错,可指定兼容版本下载:

curl -O https://github.com/erlang/rebar3/releases/download/3.22.1/rebar3

(3.22.1为兼容OTP22的稳定版本,可按需调整)

3. 清理项目缓存(针对项目内rebar3问题)

若在特定项目中触发异常,进入项目目录清理缓存并重建:

rm -rf _build
rebar3 clean
rebar3 compile

4. 检查环境变量配置

确保~/.local/bin在系统PATH中:

echo $PATH | grep ~/.local/bin

若未找到,将其添加到shell配置文件(如~/.bashrc或~/.zshrc):

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 09:15:13