Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[elixir] Unable to load project dependencies via iex -S mix #926

Closed
thepeoplesbourgeois opened this issue Apr 21, 2021 · 20 comments
Closed

Comments

@thepeoplesbourgeois
Copy link

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.

@Stratus3D
Copy link
Member

@thepeoplesbourgeois commands like iex -S mix deps.compile work for me with the same version of asdf and the same version of Elixir. Are you using the latest version of the Elixir plugin? asdf plugin-update elixir?

@thepeoplesbourgeois
Copy link
Author

thepeoplesbourgeois commented Apr 22, 2021

Assuming that's the version that gets downloaded when you do asdf plugin remove elixir; asdf plugin add elixir, then yes.

Quick check: are you running bash, zsh, or other?

@thepeoplesbourgeois
Copy link
Author

thepeoplesbourgeois commented Apr 22, 2021

...Huh. Now that I've asked someone to come look at the error I'm getting, I'm not getting the error anymore...

I guess COVID-19 really has made work-from-home the new normal.

(get vaccinated, for the love of Git)

@cippaciong
Copy link

Hi, I just installed asdf and I'm having exactly the same error when I try to run iex -S mix in a newly created Phoenix project.

$ iex -S mix
Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]

** (SyntaxError) /Users/tommasosardelli/.asdf/shims/mix:5:54: syntax error before: "$@"
    (elixir 1.12.3) lib/code.ex:1261: Code.require_file/2
$ cat ~/.asdf/shims/mix
#!/usr/bin/env bash
# asdf-plugin: elixir 1.11.4
# asdf-plugin: elixir 1.11.4-otp-23
# asdf-plugin: elixir 1.12.3-otp-24
exec /usr/local/opt/asdf/libexec/bin/asdf exec "mix" "$@"
$ asdf current
elixir          system          /Users/tommasosardelli/.tool-versions
erlang          system          /Users/tommasosardelli/.tool-versions

@Stratus3D
Copy link
Member

@cippaciong did you try running asdf reshim after installing Elixir? Make sure you are using the latest version of asdf and asdf-elixir. If you still encounter the issue can you paste the output of asdf info here?

@cippaciong
Copy link

@Stratus3D I tried running asdf reshim after your comment but it didn't solve the problem.

I noticed that the error occurs when I'm using the "system" Elixir (installed with Homebrew) which is my global default, but not when using an Elixir version installed with asdf (i.e. if I run asdf local elixir 1.11.4 and then iex -S mix, it works).

Here is the output of asdf info:

OS:
Darwin MacBook-Pro-di-Tommaso.local 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64 x86_64

SHELL:
GNU bash, version 5.1.8(1)-release (x86_64-apple-darwin20.3.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.1

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

ASDF INSTALLED PLUGINS:
elixir                       https://github.com/asdf-vm/asdf-elixir.git
erlang                       https://github.com/asdf-vm/asdf-erlang.git

I installed both elixir and erlang plugins yesterday for the first time so they should be up-to-date.

@Stratus3D
Copy link
Member

@cippaciong are you sure you've set the system version correctly? Does it point to the root of an elixir build? What does asdf current output for you?

@cippaciong
Copy link

I'm not sure I understand what you mean with set the system version correctly? Do you mean if I'm sure that the system version is a valid elixir installation? In that case yes.

$ asdf current
elixir          system          /Users/tommasosardelli/.tool-versions
erlang          system          /Users/tommasosardelli/.tool-versions
$ cat /Users/tommasosardelli/.tool-versions
elixir system
erlang system
$ asdf which elixir
/usr/local/bin/elixir
$ ls -l /usr/local/bin/elixir
lrwxr-xr-x  1 tommasosardelli  admin  34 Sep  6 09:33 /usr/local/bin/elixir -> ../Cellar/elixir/1.12.3/bin/elixir

$ ls -l /usr/local/Cellar/elixir/1.12.3/bin/
total 40
-r-xr-xr-x  1 tommasosardelli  staff  6332 Sep  5 10:02 elixir
-r-xr-xr-x  1 tommasosardelli  staff  1326 Sep  5 10:02 elixirc
-r-xr-xr-x  1 tommasosardelli  staff   805 Sep  5 10:02 iex
-r-xr-xr-x  1 tommasosardelli  staff    49 Sep  5 10:02 mix
$ /usr/local/bin/elixir --version
Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]

Elixir 1.12.3 (compiled with Erlang/OTP 24)

@Stratus3D
Copy link
Member

Sorry @cippaciong , I was juggling a couple issues and confused myself. I was thinking you had a path version set, not a system version set. In this case I'd see what type -a elixir returns (or that same command for any other executable provided by Elixir). It should reveal which system elixir asdf will fall back to.

@cippaciong
Copy link

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

@Stratus3D
Copy link
Member

@cippaciong and if you invoke /usr/local/bin/iex directly it works? I'm not sure what the issue is. It could either be something funky on your system that is interfering with asdf, or it could be a bug in asdf itself.

@cippaciong
Copy link

@Stratus3D invoking it with usr/local/bin/iex -S /usr/local/bin/mix works, while using usr/local/bin/iex -S mix doesn't

$ /usr/local/bin/iex -S /usr/local/bin/mix
Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]

Interactive Elixir (1.12.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
$ /usr/local/bin/iex -S mix
Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]

** (SyntaxError) /Users/tommasosardelli/.asdf/shims/mix:5:54: syntax error before: "$@"
    (elixir 1.12.3) lib/code.ex:1261: Code.require_file/2

@Stratus3D
Copy link
Member

@cippaciong not sure what is going on. I don't have a system version of elixir configured so I don't have a good way to test this. This is definitely something I've heard from other people - see asdf-vm/asdf-elixir#62 for an example. I've not been able to nail down what the cause is. It may be a bug but it may not be.

@cippaciong
Copy link

I see, I'll try to investigate further when I have some time. Thank you for your help @Stratus3D

@younesmln
Copy link

@cippaciong

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

Based on your terminal output, it looks like you have duplication installations of elixir, elixirc, iex and mix.
A solution to your problem could be only keeping the asdf installation by using something like this:

sudo rm /usr/local/bin/{iex,mix,elixirc,elixir}

@SamJakob
Copy link

SamJakob commented Jan 7, 2023

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.

@dkuku
Copy link

dkuku commented Nov 21, 2023

@Stratus3D
It looks like iex should get path to mix but it's getting the line from asdf and fails on that??

╰─➤  iex -S mix run --no-start
** (SyntaxError) /Users/kuku/.asdf/shims/mix:22:18: syntax error before: '.'
    |
 22 | exec /Users/kuku/.asdf/bin/asdf exec "mix" "$@"
    |                  ^
    (elixir 1.15.2) lib/code.ex:1435: Code.require_file/2

When replacing the mix with a direct path it works:

╰─➤  iex -S ~/.asdf/installs/elixir/1.13.3-otp-24/bin/mix run --no-start                                                                                                                1 ↵
Erlang/OTP 24 [erts-12.3.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

==> my_app

@Stratus3D
Copy link
Member

Interesting @SamJakob , can anyone else here test that and confirm is that fixes the issue?

I believe this is the same issue as asdf-vm/asdf-elixir#111 so lets continue discussion there since that issue is still open.

@pojiro
Copy link

pojiro commented Jan 14, 2024

@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)> 

@Stratus3D
Copy link
Member

Please keep all discussion on the open issue - asdf-vm/asdf-elixir#111

@asdf-vm asdf-vm locked as off-topic and limited conversation to collaborators Jan 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants