首次创建Elixir项目执行mix ecto.create时mint依赖编译报错
Mix Ecto.Create 编译Mint依赖失败问题排查
首次搭建Elixir项目时执行mix ecto.create,触发以下错误:
could not compile dependency :mint, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile mint --force", update it with "mix deps.update mint" or clean it with "mix deps.clean mint"
对应的编译日志:
==> mint Compiling 1 file (.erl) src/mint_shims.erl:37:14: can't find include lib "public_key/include/public_key.hrl" % 37| -include_lib("public_key/include/public_key.hrl"). % | ^ src/mint_shims.erl:64:21: undefined macro 'id-ce-subjectAltName' % 64| try lists:keyfind(?'id-ce-subjectAltName', % | ^ src/mint_shims.erl:39:2: function pkix_verify_hostname/3 undefined % 39| -export([pkix_verify_hostname/2, pkix_verify_hostname/3]). % | ^ src/mint_shims.erl:42:36: record 'OTPCertificate' undefined % 42| -spec pkix_verify_hostname(Cert :: #'OTPCertificate'{} | binary(), % | ^ src/mint_shims.erl:45:2: spec for undefined function pkix_verify_hostname/3 % 45| -spec pkix_verify_hostname(Cert :: #'OTPCertificate'{} | binary(), % | ^ src/mint_shims.erl:45:36: record 'OTPCertificate' undefined % 45| -spec pkix_verify_hostname(Cert :: #'OTPCertificate'{} | binary(), % | ^ src/mint_shims.erl:52:5: function pkix_verify_hostname/3 undefined % 52| pkix_verify_hostname(Cert, ReferenceIDs, []). % | ^ src/mint_shims.erl:114:1: Warning: function verify_hostname_extract_fqdn_default/1 is unused % 114| verify_hostname_extract_fqdn_default({dns_id,S}) -> % | ^ src/mint_shims.erl:122:1: Warning: function verify_hostname_fqnds/2 is unused % 122| verify_hostname_fqnds(L, FqdnFun) -> % | ^ src/mint_shims.erl:139:1: Warning: function verify_hostname_match_default/2 is unused % 139| verify_hostname_match_default(Ref, Pres) -> % | ^ src/mint_shims.erl:142:1: Warning: function verify_hostname_match_default0/2 is unused % 142| verify_hostname_match_default0(FQDN=[_|_], {cn,FQDN}) -> % | ^ src/mint_shims.erl:182:1: Warning: function ok/1 is unused % 182| ok({ok,X}) -> X. % | ^ src/mint_shims.erl:184:1: Warning: function l16_to_tup/1 is unused % 184| l16_to_tup(L) -> list_to_tuple(l16_to_tup(L, [])). % | ^ src/mint_shims.erl:186:1: Warning: function l16_to_tup/2 is unused % 186| l16_to_tup([A,B|T], Acc) -> l16_to_tup(T, [(A bsl 8) bor B | Acc]); % | ^ src/mint_shims.erl:189:1: Warning: function match_wild/2 is unused % 189| match_wild(A, [$*|B]) -> match_wild_suffixes(A, B); % | ^ src/mint_shims.erl:195:1: Warning: function match_wild_suffixes/2 is unused % 195| match_wild_suffixes(A, B) -> match_wild_sfx(lists:reverse(A), lists:reverse(B)). % | ^ src/mint_shims.erl:197:1: Warning: function match_wild_sfx/2 is unused % 197| match_wild_sfx([$*|_], _) -> false; % Bad name (no wildcards allowed) % | ^ src/mint_shims.erl:204:1: Warning: function verify_hostname_match_loop/5 is unused % 204| verify_hostname_match_loop(Refs0, Pres0, undefined, FailCB, Cert) -> % | ^ src/mint_shims.erl:227:1: Warning: function to_lower_ascii/1 is unused % 227| to_lower_ascii({ip,_}=X) -> X; % | ^ src/mint_shims.erl:234:1: Warning: function to_string/1 is unused % 234| to_string(S) when is_list(S) -> S; % | ^
已尝试重新安装所有组件,怀疑是否为PostgreSQL问题。
问题根源
这不是PostgreSQL的问题,核心原因是Erlang环境缺少public_key应用相关的依赖文件,或者编译时无法正确加载该应用。public_key是Erlang/OTP自带的标准库,负责证书处理等加密操作,Mint依赖它完成HTTPS相关的逻辑。
解决方案
按以下步骤排查修复:
检查Erlang版本兼容性
确认当前使用的Erlang版本与Mint依赖要求匹配。查看当前Erlang版本:erl -version如果版本过旧,建议升级到最新稳定版(如OTP 25+),部分旧版本可能存在
public_key组件缺失或路径问题。强制重新编译Mint并指定依赖路径
执行以下命令,强制重新编译Mint时确保public_key被正确引入:mix deps.compile mint --force --extra-apps public_key验证Erlang环境中public_key是否可用
打开Erlang shell,执行以下命令测试public_key是否正常加载:application:ensure_all_started(public_key).返回
{ok, [public_key, crypto, asn1]}说明正常;若返回错误,需重新安装Erlang,确保安装过程未忽略标准库组件。清理并重新获取所有依赖
若以上步骤无效,彻底清理依赖后重新安装:mix deps.clean --all mix deps.get mix deps.compile检查系统级依赖(针对Linux/macOS)
- Linux:确保安装
libssl-dev(Debian/Ubuntu)或openssl-devel(RHEL/CentOS),Erlang的public_key依赖OpenSSL库。 - macOS:通过Homebrew重新安装Erlang,确保编译时包含OpenSSL支持:
brew reinstall erlang
- Linux:确保安装
内容的提问来源于stack exchange,提问作者BrownieGD
相关产品推荐
相关产品推荐

