Elixir-ls fails to start due to hex issues

I used to manage all of my Elixir stuff with ASDF but I’ve been consulting on a Ruby project and mise seemed to work better there so I made the switch. However, this seems to have broken my Elixir LSPs. I don’t know too much about what’s going on under the hood with Hex so forgive my ignorance here.

If I run mix hex.info I get this:

Hex:    2.4.1
Elixir: 1.19.5
OTP:    28.3

Built with: Elixir 1.19.5 and OTP 28.4.1

However, if I then run elixir-ls I get this:

Running /Users/travis/.local/share/mise/installs/elixir-ls/0.30.0/launch.sh
Preferred shell is zsh, relaunching
Looking for asdf install
Legacy asdf not found at /Users/travis/.asdf/asdf.sh
unknown command: elixir. Perhaps you have to reshim?
Running setup script /Users/travis/.config/elixir_ls/setup.sh
Installing ElixirLS release v0.30.0
Running in /Users/travis/Documents/my_project
* Updating elixir_ls (https://github.com/elixir-lsp/elixir-ls.git - v0.30.0)
==> language_server
Could not find Hex, which is needed to build dependency :stream_data
Shall I install Hex? (if running non-interactively, use "mix local.hex --force")
* creating /Users/travis/.local/share/mise/installs/elixir/1.19.5-otp-28/.mix/archives/hex-2.4.1
Could not start Hex. Try fetching a new version with "mix local.hex" or uninstalling it with "mix archive.uninstall hex.ez"
Mix.install failed with ** (UndefinedFunctionError) function Hex.start/0 is undefined (module Hex is not available)
    Hex.start()
    (mix 1.13.4) lib/mix/hex.ex:59: Mix.Hex.start/0
    (mix 1.13.4) lib/mix/dep/loader.ex:203: Mix.Dep.Loader.with_scm_and_app/4
    (mix 1.13.4) lib/mix/dep/loader.ex:156: Mix.Dep.Loader.to_dep/3
    (elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
    (elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
    (mix 1.13.4) lib/mix/dep/loader.ex:373: Mix.Dep.Loader.mix_children/2
    (mix 1.13.4) lib/mix/dep/loader.ex:331: anonymous fn/4 in Mix.Dep.Loader.mix_dep/2

Retrying Mix.install with force: true

I’ve run mix archive uninstall hex.ez and reinstalled hex (this was before getting the above yet again).

Something that may or may not be related is simply running mix hex I get this warning:

07:00:27.523 [error] beam/beam_load.c(219): Error loading module 'Elixir.Hex':
  This BEAM file was compiled for an old version of the runtime system.
  To fix this, please re-compile this module with Erlang/OTP 25 or later.



Mix requires the Hex package manager to fetch dependencies
Shall I install Hex? (if running non-interactively, use "mix local.hex --force") [Yn]

There have been a few, project specific, occasions where something like elixir-ls would start working in my terminal, however it would crash in in Zed or Sublime right around the Could not start Hex. Try fetching a new version....

Looks like you still have asdf installed. You should remove it entirely for that launch script to use mise.

Thanks, you are correct I did still have some ASDF artifacts lying around which I’ve removed but the error remains, effectively the same:

Running /Users/travis/.local/share/mise/installs/elixir-ls/0.30.0/launch.sh
Preferred shell is zsh, relaunching
Looking for asdf install
asdf not found
Looking for mise executable
mise executable found at /Users/travis/.local/bin/mise, activating
Running setup script /Users/travis/.config/elixir_ls/setup.sh
Installing ElixirLS release v0.30.0
Running in /Users/travis/Documents/postbox
* Updating elixir_ls (https://github.com/elixir-lsp/elixir-ls.git - v0.30.0)
==> language_server
Could not find Hex, which is needed to build dependency :stream_data
Shall I install Hex? (if running non-interactively, use "mix local.hex --force")
* creating /Users/travis/.local/share/mise/installs/elixir/1.19.5-otp-28/.mix/archives/hex-2.4.1
Could not start Hex. Try fetching a new version with "mix local.hex" or uninstalling it with "mix archive.uninstall hex.ez"
Mix.install failed with ** (UndefinedFunctionError) function Hex.start/0 is undefined (module Hex is not available)
    Hex.start()
    (mix 1.13.4) lib/mix/hex.ex:59: Mix.Hex.start/0
    (mix 1.13.4) lib/mix/dep/loader.ex:203: Mix.Dep.Loader.with_scm_and_app/4
    (mix 1.13.4) lib/mix/dep/loader.ex:156: Mix.Dep.Loader.to_dep/3
    (elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
    (elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
    (mix 1.13.4) lib/mix/dep/loader.ex:373: Mix.Dep.Loader.mix_children/2
    (mix 1.13.4) lib/mix/dep/loader.ex:331: anonymous fn/4 in Mix.Dep.Loader.mix_dep/2

I am a bit perplexed on why would you need elixir-ls managed by asdf or mise at all? Why not let your code editor manage it?

1 Like

Generally I do, I was just playing around with it locally in my terminal to see if it would run. If I mise unuse elixir-ls and let Zed handle it the error message is the same from the Zed lsp logs. The logging from Sublime isn’t quite as detailed but I suspect the same error is at the heart of those issues as well.