Open jarmo opened 2 years ago
After installing Erlang 23.0 and Elixir 1.11.2 with asdf and using them instead of system installations then everything seems to work.
@jarmo so this seems to be limited to when you tried to run iex -S mix phx.server
with the system Erlang and Elixir versions?
Can you share the output of asdf info
? Thanks!
Yes, as soon as I don't specify local erlang/elixir system
, but specify same versions of Erlang/Elixir installed by asdf then everything seems to work as expected.
$ asdf info
OS:
Linux caesar 4.4.0-19041-Microsoft #1237-Microsoft Sat Sep 11 14:32:00 PST 2021 x86_64 x86_64 x86_64 GNU/Linux
SHELL:
zsh 5.1.1 (x86_64-ubuntu-linux-gnu)
ASDF VERSION:
v0.8.1-a1ef92a
ASDF ENVIRONMENT VARIABLES:
ASDF_DIR=/home/jarmo/.asdf
ASDF INSTALLED PLUGINS:
elixir https://github.com/asdf-vm/asdf-elixir.git
erlang https://github.com/asdf-vm/asdf-erlang.git
Now, before Microsoft
causes any confusion then the real "OS" is Ubuntu 16.04 inside WSL-1:
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.7 LTS"
Did you have Erlang and Elixir installed on your system prior to asdf? And did they work when you ran simple things like just erl
or iex
?
Yes, Erlang 23.0 and Elixir 1.11.2 were installed before and I used iex -S mix phx.server
pretty often for development. Until yesterday asdf was not installed on my machine, but I needed newest versions of Erlang and Elixir to try out the newest version of Phonenix Framework, which made me to look into asdf, since I didn't want to cause any issues to my older project by upgrading Erlang and Elixir system-wide.
When I comment out asdf in my .zshrc
then I can use iex -S mix phx.server
for my older project without any issues as was the case before installing asdf.
Also, as mentioned when I install the same versions of Erlang and Elixir with asdf and set them as local versions for the same older project then everything works too so it's not that big of a problem that system installations will not work - I can even uninstall them since everything works with asdf too.
Does this issue appear similar to yours? https://github.com/asdf-vm/asdf/issues/1130
Also, what happens if you run asdf reshim
and then try the system version with asdf?
asdf reshim
does not seem to make any difference.
Some additional information:
$ cat .tool-versions
erlang system
elixir system
$ which erl
/home/jarmo/.asdf/shims/erl
$ which elixir
/home/jarmo/.asdf/shims/elixir
$ iex -S mix phx.server
Erlang/OTP 23 [erts-11.1.7] [source] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [hipe]
** (SyntaxError) /home/jarmo/.asdf/shims/mix:4:18: syntax error before: '.'
(elixir 1.11.2) lib/code.ex:931: Code.require_file/2
$ asdf reshim
$ iex -S mix phx.server
Erlang/OTP 23 [erts-11.1.7] [source] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [hipe]
** (SyntaxError) /home/jarmo/.asdf/shims/mix:4:18: syntax error before: '.'
(elixir 1.11.2) lib/code.ex:931: Code.require_file/2
$ cp -f .tool-versions.bck .tool-versions
$ cat .tool-versions
erlang 23.0
elixir 1.11.2
$ iex -S mix phx.server
Erlang/OTP 23 [erts-11.0] [source] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [hipe]
[info] Running MyWeb.Endpoint with cowboy 2.9.0 at 0.0.0.0:4000 (https)
...
Also this:
$ asdf list
elixir
1.11.2
1.13.1-otp-24
erlang
23.0
24.2
This looks like the same issue - https://github.com/asdf-vm/asdf-elixir/issues/62
Have you tried updating the plugin? asdf plugin-update elixir
?
No, I have not tried to update anything since I did install asdf and all of its plugins last week for the first time ever.
Hmm... I'm out of ideas. What is the output of type -a iex
and type -a mix
? Do you happen to have any other version managers or anything else on your system that may interfere with asdf?
$ type -a iex
iex is /home/jarmo/.asdf/shims/iex
iex is /usr/bin/iex
$ type -a mix
mix is /home/jarmo/.asdf/shims/mix
mix is /usr/bin/mix
About other version managers - I have only chruby installed for managing Rubies, but not anything else for Elixir/Erlang.
That all looks correct. chruby shouldn't be a problem. The only thing I can think of is maybe something is wrong with your shims and asdf reshim
isn't fixing it. You could try deleting all your shims (rm /home/jarmo/.asdf/shims/*
) and then running asdf reshim
to re-generate them. I'm not sure this would fix anything though. I'm out of ideas.
Nope, didn't help. Here's my shim for mix
:
$ cat ~/.asdf/shims/mix
#!/usr/bin/env bash
# asdf-plugin: elixir 1.11.2
# asdf-plugin: elixir 1.13.1-otp-24
exec /home/jarmo/.asdf/bin/asdf exec "mix" "$@"
I did read that WSL1 is not officially supported by asdf - can it be that this is the reason behind this problem although everything else seems to work as expected so far?
No need to even execute phx.server
:
$ iex -S mix
Erlang/OTP 23 [erts-11.1.7] [source] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [hipe]
** (SyntaxError) /home/jarmo/.asdf/shims/mix:4:18: syntax error before: '.'
(elixir 1.11.2) lib/code.ex:931: Code.require_file/2
Yeah I'm at a loss. I have no idea what the issue is. You might check this issue tracker for others who have encountered issues on WSL. I am not familiar with WSL and it isn't officially supported by asdf as far as I know.
I'm having a similar problem on Mac OS, where system versions of erlang, elixir and hex were installed before I added asdf.
When I'm inside a Phoenix project and run iex -S mix phx.new
I get the same error as @jarmo. However, using the slightly more convoluted asdf exec iex -S mix phx.server
works fine. Smells like some kind of path issue, but right now I'm not smart enough to see how it can be solved to work as usual.
Edit:
It seems to be related to the line . $HOME/.asdf/asdf.sh
in my shell-config (~/.zshrc) that I added during asdf installation, or rather, the referenced file asdf.sh
. Outcommenting that line gives me access to the system version of elixir (1.13.1) and I can still use asdf exec iex -S mix phx.server
to get the asdf version.
For me using asdf exec
as a command prefix still results in the same error as without.
Somehow, between outcommenting the the line . $HOME/.asdf/asdf.sh
, checking different shell scripts and undoing the uncomment, something changed for the better and now everything works without problems. So for me it was some path problem.
@Stratus3D
As far as I can tell what is happening is that asdf prepends to $PATH
for asdf-elixir managed installations, but not for system installations (a.k.a., whatever it finds in $PATH
)
(What it prepends is $ASDF_PREFIX/plugins/elixir/shims:$ASDF_PREFIX/installs/elixir/$VERSION/bin:$ASDF_PREFIX/installs/elixir/$VERSION/.mix/escripts:
)
iex -S $script
assumes/requires $script
to be the name of an elixir script in $PATH
(or the path to one https://github.com/asdf-vm/asdf/issues/926#issuecomment-916917080).
This is why with asdf {global,local} elixir system
, iex -S mix
looks for mix
in $PATH
, sees the bash script $ASDF_PREFIX/shims/mix
, tries to load it, fails.
Aside: $ASDF_PREFIX/plugins/elixir/shims
doesn't contain anything executable so it doesn't seem to affect anything
@MathiasWedeken good to know. I use asdf and elixir every day and don't encounter this issue. I suspect there could be an environmental element to this issue. Perhaps something else on the path, or some iex configuration affects this behavior. But in any case if you follow the instructions in the asdf docs you should have a working setup.
@AviKav asdf put its' shims on your $PATH
, and those shims may point to asdf-managed version, or, if you've specified a system version, the version already installed on your system. Assuming iex
is executing the script given with the -S
this should all work. However I still don't understand why it works for me and not for others.
@Stratus3D
asdf put its' shims on your $PATH
Not all the time. While asdf's rc scripts amends $PATH
so it points to the shims first, the shims, when called, amend $PATH
so that they aren't pointed to first.
The problem is that they don't/can't do this for system installs
Assuming iex is executing the script given with the -S this should all work.
That would indeed be the case if iex
was executing them via exec()
family and not trying to read them
However I still don't understand why it works for me and not for others.
You mentioned half a year ago not having a system
install to use with asdf. Is this still the case?
https://github.com/asdf-vm/asdf/issues/926#issuecomment-917188213
I think you may be able to make asdf think you have a system install available by adding an elixir install to '$PATH' before sourcing asdf
@Stratus3D
But in any case if you follow the instructions in the asdf docs you should have a working setup.
I'm pretty sure that I followed asdf instructions in the doc and did the same when installing Elixir/Erlang long before installing asdf. I don't think that I have done anything to steer off the path of "official" way of installing/loading either of these.
I have created two Dockerfiles to reproduce this problem.
First is a Docker file, which uses only system installation to show that it works as expected:
# Dockerfile.system
FROM ubuntu
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update -y
RUN apt upgrade -y
RUN apt install -y wget
# System installation of Erlang and Elixir according to https://elixir-lang.org/install.html
RUN wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && apt install -y --fix-broken ./erlang-solutions_2.0_all.deb
RUN apt update -y
RUN apt install -y esl-erlang
RUN apt install -y elixir
WORKDIR /home/elixir
CMD iex -S mix help
It works as expected:
$ docker build -t elixir-test -f Dockerfile.system . && docker run --rm -it elixir-test
Erlang/OTP 24 [erts-12.3] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit]
...
Interactive Elixir (1.13.0) - press Ctrl+C to exit (type h() ENTER for help)
Now, let's add Dockerfile for asdf:
# Dockerfile.asdf
FROM ubuntu
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update -y
RUN apt upgrade -y
RUN apt install -y wget
# System installation of Erlang and Elixir according to https://elixir-lang.org/install.html
RUN wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && apt install -y --fix-broken ./erlang-solutions_2.0_all.deb
RUN apt update -y
RUN apt install -y esl-erlang
RUN apt install -y elixir
# asdf installation of Erlang and Elixir
RUN apt install -y curl git build-essential libssl-dev automake autoconf libncurses5-dev
RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.9.0
RUN echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
RUN bash -ic "asdf plugin add erlang && \
asdf install erlang latest && \
asdf plugin add elixir && \
asdf install elixir latest"
WORKDIR /home/elixir
CMD bash -ic "asdf local erlang latest && asdf local elixir latest && iex -S mix help"
#CMD bash -ic "asdf local erlang system && asdf local elixir system && iex -S mix help"
This also works as expected:
$ docker build -t elixir-test -f Dockerfile.asdf . && docker run --rm -it elixir-test
Erlang/OTP 24 [erts-12.3] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit]
...
Interactive Elixir (1.13.3) - press Ctrl+C to exit (type h() ENTER for help)
However, when you uncomment last CMD
line in Dockerfile.asdf
so that system
versions of Elixir and Erlang would be used then problems happen:
$ docker build -t elixir-test -f Dockerfile.asdf . && docker run --rm -it elixir-test
** (SyntaxError) /root/.asdf/shims/mix:3:12: syntax error before: '.'
|
3 | exec /root/.asdf/bin/asdf exec "mix" "$@"
| ^
(elixir 1.13.0) lib/code.ex:1183: Code.require_file/2
Hope this helps.
Thanks for the Dockerfile @jarmo ! That helps some, however I've got a coworker who has this same issue manifesting with regular versions, not system versions. Have you or anyone else here encountered that?
@Stratus3D you're welcome about Dockerfiles. I've only encountered this issue as is happening with reproducible Dockerfiles above. Not had issues like that in any other way yet.
Have same issue. When install erlang localy, i added ERL_LIBS env in my .bashrc file. After remove it - all was fixed.
Hitting this same issue, interestingly asdf worked correctly in one project, but not the other.
There was a slight difference in the .tool-versions
file between the projects:
The non-working one:
cat .tool-versions
elixir 1.14.0
erlang 25.0.4
The working one:
cat .tool-versions
elixir 1.14
erlang 25.0.4
After changing elixir 1.14.0
to elixir 1.14
in the .tool-versions
, I could launch iex -S mix
again.
I've experienced the same issue with system
elixir. Described it here https://github.com/jfpedroza/neotest-elixir/issues/16
I'm having this issue today and have never had a problem. I don't know what caused this.
Fixed (YMMV):
Okay, I don't know what was happening as I had just installed the versions of Elixir and Erlang I was using. I tried to reshim, and that didn't fix it. I decided to do asdf uninstall elixir 1.14.4-otp-25
. Then I did asdf install
. The problem went away and it started working correctly. I don't like that I have no understanding of why it was broken, but if you need it to work maybe this is a good solution.
I have the same problem with ASDF and elixir.
Installed asdf the first time last Friday, today I needed to switch back to "system" elixir, added the system in tool-versions, did a reshim
as suggested in this thread. I'm on MacOS and run the latest OSX.
Tool versions:
elixir system 1.15.0-otp-25
erlang system 25.3.2.2
Reverting the path -- essentially cutting off ASDF -- "fixes" the problem. Was there ever a correct fix found?
I seem to need my system erlang/elixir to get elixir-ls running again -- this is of course unrelated to this bug.
Here's my asdf info
output. This is in a shell where ASDF is still in the path:
❯ asdf info
OS:
Darwin NewEden 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64 x86_64
SHELL:
zsh 5.9 (x86_64-apple-darwin22.0)
BASH VERSION:
3.2.57(1)-release
ASDF VERSION:
v0.12.0
ASDF INTERNAL VARIABLES:
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=.tool-versions
ASDF_DATA_DIR=/Users/seletz/.asdf
ASDF_DIR=/usr/local/opt/asdf/libexec
ASDF_CONFIG_FILE=/Users/seletz/.asdfrc
ASDF INSTALLED PLUGINS:
elixir https://github.com/asdf-vm/asdf-elixir.git master a4c42e1
erlang https://github.com/asdf-vm/asdf-erlang.git master 267f6bb
Here's what the shell's path resolver thinks. I'm using ZSH
.
❯ type -a iex
iex is /Users/seletz/.asdf/shims/iex
iex is /usr/local/bin/iex
iex is /usr/local/bin/iex
❯ type -a elixir
elixir is /Users/seletz/.asdf/shims/elixir
elixir is /usr/local/bin/elixir
elixir is /usr/local/bin/elixir
❯ type -a erl
erl is /Users/seletz/.asdf/shims/erl
erl is /usr/local/bin/erl
erl is /usr/local/bin/erl
Same issue with newest asdf & elixir & erlang when elixie is installed before asdf and use system version.
Same problem. What I'd like is to default to the system versions of things and then have specific versions for some projects. I've got a global .tool-versions
with system
specified for everything, but doing so breaks iex -S mix
because iex
tries to load the shim even though the shim just redirects right back to the system installation.
If I specify a specific version of Elixir, then everything works completely fine.
Edit: Found a workaround: iex -S /usr/bin/mix phx.server
. It's a bit awkward, but it works. It even works when using something other than the system Elixir installation, since /usr/bin/mix
is just a script that calls Mix.CLI.main()
, and that'll just use the module for the Elixir installation, not the one that installed the file at /usr/bin/mix
.
I just encountered the exact same issue and the reason for me was that my asdf elixir installation directory was completely empty but there was a system elixir that asdf seemingly was falling back to, causing the strange error. After uninstall re-installing the broken elixir version everything was fine again:
> iex -S mix
Erlang/OTP 24 [erts-12.3.2.13] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
** (SyntaxError) /root/.asdf/shims/mix:3:12: syntax error before: '.'
|
3 | exec /root/.asdf/bin/asdf exec "mix" "$@" # asdf_allow: ' asdf '
| ^
(elixir 1.13.0) lib/code.ex:1183: Code.require_file/2
> cat .tool-versions
elixir 1.13.4-otp-24
> asdf install
elixir 1.13.4-otp-24 is already installed
> asdf list elixir
*1.13.4-otp-24
1.13.4
> ls ~/.asdf/installs/elixir/1.13.4-otp-24/
> asdf uninstall elixir 1.13.4-otp-24
> asdf install elixir 1.13.4-otp-24
> iex -S mix
Erlang/OTP 24 [erts-12.3.2.13] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
==> credo
Compiling 251 files (.ex)
...
(all fine now)
Running
iex -S mix phx.server
fails:Running
mix phx.server
seems to work without any issues.Erlang and Elixir are
system
installations on Ubuntu 16.04.