asdf: [elixir] Unable to load project dependencies via `iex -S mix`

Describe the bug

When asdf has the Elixir plugin and any available version installed, running iex -S mix [TASK] fails, preventing a user from being able to load a project’s package dependencies into the REPL, and/or from running any task (e.g., deps.compile, phx.server) within the context of the REPL. The problem seems to stem from the way the mix shim loads Bash args (works as expected in zsh), as the error message on exit is

** (SyntaxError) ~/.asdf/shims/mix:4:46: syntax error before: "$@"
    (elixir 1.11.4) lib/code.ex:931: Code.require_file/2
------- ~/.asdf/shims/mix

#!/usr/bin/env bash
# asdf-plugin: elixir 1.12.0-rc.0
# asdf-plugin: elixir 1.11.4
exec /usr/local/opt/asdf/bin/asdf exec "mix" "$@"

To Reproduce

Make sure you are executing in Bash:

$ asdf plugin add elixir
$ asdf install elixir 1.11.4
$ mix new something && cd something
$ iex -S mix

Expected behavior

The terminal should have given you an output and prompt such as:

Erlang/OTP 23 [erts-11.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]

Compiling 1 file (.ex)
Generated something app
Interactive Elixir (1.11.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 

Actual behavior

You most likely saw the error as reported above.

I’ve narrowed down the shim as the definite source of the issue, as I produced the expected behavior example for this issue by running $(asdf which iex) -S $(asdf which mix).

Environment

OS:
Darwin Newtons-Mac-mini 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64

SHELL:
GNU bash, version 5.1.4(1)-release (x86_64-apple-darwin20.2.0)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

ASDF VERSION:
v0.8.0

ASDF ENVIRONMENT VARIABLES:
ASDF_DIR=/usr/local/opt/asdf

ASDF INSTALLED PLUGINS:
elixir                       https://github.com/asdf-vm/asdf-elixir.git
erlang                       https://github.com/asdf-vm/asdf-erlang.git
julia                        https://github.com/rkyleg/asdf-julia.git
python                       https://github.com/danhper/asdf-python.git

asdf plugins affected (if relevant):

Just asdf-elixir, but it looks like asdf-python may have a similar issue? It doesn’t seem to like it when I try to run pip --help.

Additional context

This is the first day of the rest of your life.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (8 by maintainers)

Most upvoted comments

For anyone getting this problem right after installing, I had this exact problem as when I’d installed Elixir and Erlang with asdf, I hadn’t properly restarted my Terminal, instead just re-running zsh. Closing and re-opening the Terminal fixed the issue.

@Stratus3D I could confirm.

issue happens

erl -noshell -elixir_root /home/pojiro/.asdf/installs/elixir/1.15.7-otp-26/bin/../lib -pa /home/pojiro/.asdf/installs/elixir/1.15.7-otp-26/bin/../lib/elixir/ebin -s elixir start_iex -elixir ansi_enabled true -user elixir -extra --no-halt +iex -S mix
** (SyntaxError) /home/pojiro/.asdf/shims/mix:6:19: syntax error before: '.'
    |
  6 | exec /home/pojiro/.asdf/bin/asdf exec "mix" "$@" # asdf_allow: ' asdf '
    |                   ^
    (elixir 1.15.7) lib/code.ex:1435: Code.require_file/2
erl -noshell -elixir_root /home/pojiro/.asdf/installs/elixir/1.15.7-otp-26/bin/../lib -pa /home/pojiro/.asdf/installs/elixir/1.15.7-otp-26/bin/../lib/elixir/ebin -s elixir start_iex -elixir ansi_enabled true -user elixir -extra --no-halt +iex -S /home/pojiro/.asdf/shims/mix
** (SyntaxError) /home/pojiro/.asdf/shims/mix:6:19: syntax error before: '.'
    |
  6 | exec /home/pojiro/.asdf/bin/asdf exec "mix" "$@" # asdf_allow: ' asdf '
    |                   ^
    (elixir 1.15.7) lib/code.ex:1435: Code.require_file/2

issue not happed with mix full path

erl -noshell -elixir_root /home/pojiro/.asdf/installs/elixir/1.15.7-otp-26/bin/../lib -pa /home/pojiro/.asdf/installs/elixir/1.15.7-otp-26/bin/../lib/elixir/ebin -s elixir start_iex -elixir ansi_enabled true -user elixir -extra --no-halt +iex -S /home/pojiro/.asdf/installs/elixir/1.15.7-otp-26/bin/mix
Erlang/OTP 26 [erts-14.1.1] [source] [64-bit] [smp:32:32] [ds:32:32:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.15.7) - press Ctrl+C to exit (type h() ENTER for help)
loading /home/pojiro/.iex.exs
iex(1)> 

There you go @Stratus3D

$ for f in elixir elixirc iex mix; do type -a $f && echo; done
elixir is /Users/tommasosardelli/.asdf/shims/elixir
elixir is /usr/local/bin/elixir

elixirc is /Users/tommasosardelli/.asdf/shims/elixirc
elixirc is /usr/local/bin/elixirc

iex is /Users/tommasosardelli/.asdf/shims/iex
iex is /usr/local/bin/iex

mix is /Users/tommasosardelli/.asdf/shims/mix
mix is /usr/local/bin/mix