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

WSL环境下Phoenix项目Mix命令报错及Elixir版本查询异常求助

问题:WSL中Phoenix项目执行Mix命令报错及Elixir版本查询失败

1. Mix命令执行错误

执行任意Mix命令时均返回以下错误:

Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:10] [kernel-poll:false]

** (Mix.Config.LoadError) could not load config config/config.exs
    ** (CompileError) config/config.exs:8: module Config is not loaded and could not be found
    (elixir) lib/code.ex:168: Code.eval_string/3
    (mix) lib/mix/config.ex:161: Mix.Config.read!/1

2. 项目config.exs内容

import Config
config :timemanager,
  ecto_repos: [Timemanager.Repo]
config :timemanager, TimemanagerWeb.Endpoint,
  url: [host: "localhost"],
  render_errors: [view: TimemanagerWeb.ErrorView, accepts: ~w(json), layout: false],
  pubsub_server: Timemanager.PubSub,
  live_view: [signing_salt: "omLaBYXx"]
config :timemanager, Timemanager.Mailer, adapter: Swoosh.Adapters.Local
config :swoosh, :api_client, false
config :logger, :console,
  format: "$time $metadata[$level] $message\n",
  metadata: [:request_id]
config :phoenix, :json_library, Jason
import_config "#{config_env()}.exs"

3. Elixir版本查询错误

执行elixir -v时返回崩溃错误:

{"init terminating in do_boot",{{badmatch,error},[{'Elixir.System',build,0,[{file,"lib/system.ex"},{line,172}]},{'Elixir.System',build_info,0,[{file,"lib/system.ex"},{line,164}]},{'Elixir.Kernel.CLI',parse_shared,2,[{file,"lib/kernel/cli.ex"},{line,153}]},{'Elixir.Kernel.CLI','shared_option?',3,[{file,"lib/kernel/cli.ex"},{line,113}]},{'Elixir.Kernel.CLI',main,1,[{file,"lib/kernel/cli.ex"},{line,14}]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}
init terminating in do_boot ({{badmatch,error},[{Elixir.System,build,0,[{_},{_}]},{Elixir.System,build_info,0,[{_},{_}]},{Elixir.Kernel.CLI,parse_shared,2,[{_},{_}]},{Elixir.Kernel.CLI,shared_option?,

4. 已尝试操作与怀疑点

  • 尝试获取并升级依赖,所有Mix命令仍返回相同错误
  • 执行elixir命令可返回参数列表,但elixir -v报错
  • 怀疑是Windows终端安装的Erlang/Elixir与WSL环境冲突导致

解决方案

步骤1:清理WSL中的Windows环境变量干扰

WSL会默认继承Windows路径,可能调用了Windows下的Erlang/Elixir而非WSL本地版本。临时屏蔽Windows路径测试:

export PATH=$(echo "$PATH" | tr ':' '\n' | grep -v /mnt/c | tr '\n' ':')

执行后再次尝试elixir -v和Mix命令,若有效则永久修改WSL配置:
编辑~/.bashrc或~/.zshrc,添加上述命令,或直接重置PATH为WSL本地路径:

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

步骤2:重新在WSL中安装兼容版本的Erlang/Elixir/Phoenix

错误中显示的Erlang/OTP 20版本过低,无法支持Config模块(需Elixir 1.9+、Erlang 22+):

  1. 卸载现有Erlang/Elixir:
sudo apt remove --purge erlang elixir
sudo apt autoremove
  1. 安装兼容版本:
# 添加Erlang Solutions源
wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && sudo dpkg -i erlang-solutions_2.0_all.deb
sudo apt update
# 安装Erlang和Elixir
sudo apt install erlang elixir
# 安装Phoenix工具
mix local.hex --force
mix local.phx --force

步骤3:重置项目依赖

删除Windows环境下安装的依赖文件,重新获取:

rm -rf deps _build
mix deps.get

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 05:50:37