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

创建Elixir项目时Hex模块加载失败问题求助

修复Hex模块加载失败与OTP版本不兼容问题

问题现象

  • 本地环境:elixir -v 返回 Elixir 1.14.3 (compiled with Erlang/OTP 25)
  • 核心报错:

    [error] beam/beam_load.c(148): Error loading module 'Elixir.Hex',附带提示“please re-compile this module with an Erlang/OTP 25 compiler”
    [error] Loading of /Users/donfox1/.mix/archives/hex-0.17.1/hex-0.17.1/ebin/Elixir.Mix.Tasks.Hex.Outdated.beam failed: :badfile

  • 其他异常:项目可创建但mix compile编译失败,iex -S mix偶尔报错,单独编译文件可在iex运行;已通过Homebrew重装Elixir和Erlang,问题仍未解决。

解决方案

问题根源是本地缓存的Hex归档文件由旧版OTP编译生成,与当前OTP25不兼容,重装Elixir/Erlang不会自动更新Hex归档,执行以下步骤修复:

  1. 卸载旧Hex归档

    mix archive.uninstall hex
    
  2. 清理Mix归档缓存目录
    彻底删除旧的Hex残留文件:

    rm -rf ~/.mix/archives/
    
  3. 重新安装适配OTP25的Hex
    强制安装最新兼容版本:

    mix local.hex --force
    
  4. 验证修复效果

    • 执行mix hex.info确认Hex正常加载
    • 创建测试项目并编译验证:
      mix new test_hex_fix && cd test_hex_fix && mix compile
      

额外排查步骤(若上述操作无效)

  • 清理项目依赖缓存:进入目标项目目录执行
    rm -rf deps _build && mix deps.get && mix compile
    
  • 确认Homebrew安装的版本匹配:执行brew info erlang和brew info elixir,确保Erlang为OTP25系列,Elixir为对应编译版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 02:04:55