steveoc64

steveoc64

Noob issue getting Elixir / hello world demo running on FreeBSD 12.2-RELEASE-p1 - undefined function get_session/1

Hi all. Elixir noob here, 1st post. Apologies for the wall of text.

Trying out Elixir / Phoenix on my FreeBSD box, following the tute at Up and Running — Phoenix v1.5.8

Firstly, installed this on a fresh Ubuntu 20.10 running in a VM on the FreeBSD box, and that worked fine. Using the instructions from here - Installing Elixir - The Elixir programming language So Im confident that my procedure is correct.

On the FreeBSD host machine, I installed using
pkg install elixir

then followed the same guide as on the linux box
https://hexdocs.pm/phoenix/up_and_running.html

Get as far as mix ecto.create and then the problems begin on the FreeBSD box

Final error is

== Compilation error in file lib/plug/debugger.ex ==
** (CompileError) lib/plug/debugger.ex:277: undefined function get_session/1
    (elixir 1.10.4) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
    (stdlib 3.8.2.4) erl_eval.erl:680: :erl_eval.do_apply/6

Ive gone through the loop a few times of installing extra elixir pkgs to solve similar errors, but now Ive installed the lot, and stuck with this error. Erlang is installed, and getting in and out of both the Elixir and the Erlang repl is fine.

I can see that both get_session/1 and get_session/2 are defined in deps/plug/lib/plug/conn.ex … and if I compare those files on both my linux box and my FreeBSD box - they are identical (same md5 hash too). So its not the elixir libs at fault.

One big clue - on the FreeBSD install only - it throws a lot of warnings about redefining modules, ie - on mix ecto.create I see these sorts of warnings on a page full of libs :

warning: redefining module Plug.Session.COOKIE (current version loaded from /usr/local/lib/elixir/bin/../lib/plug/ebin/Elixir.Plug.Session.COOKIE.beam)
  lib/plug/session/cookie.ex:1

warning: redefining module Plug.Debugger (current version loaded from /usr/local/lib/elixir/bin/../lib/plug/ebin/Elixir.Plug.Debugger.beam)
  lib/plug/debugger.ex:1

… there is a couple of dozen of such warnings.

Big Clue Nr 2 - There is also a file on my system
/usr/local/lib/elixir/lib/plug/lib/plug/debugger.ex

which is different to the one pulled into deps on the hello project. That version does not call get_session anywhere, so I suspect the compiler is picking up system libs instead of dep libs.

Installed version on my system is
elixir-plug-1.4.5 Composable modules for Elixir web applications

Ideas ?

Marked As Solved

derek-zhou

derek-zhou

I strongly suggest to compile elixir yourself and do not install anything elixir related from your OS’s package manager. Elixir is fairly easy to compile, once you have erlang, which can come from your OS’s package manager, if there is a decent version on it.

Download and compile elixir from the official website, it only take a few minutes. Then, install hex packages solely through mix into the per project deps directory.

Also Liked

joaquinalcerro

joaquinalcerro

Try installing Erlang and Elixir with asdf.

I used them in FreeBSD 12.1 without a problem.

steveoc64

steveoc64

Followup from that - whilst the FreeBSD pkgs are rock solid, I need to hack on Phoenix LiveView … which in turn needs a later version of Elixir, which in turn needs a later version of Erlang.

Solution - use the erlang-runtime23 pkg supplied by FreeBSD, and as Derek suggested above, just grab the latest elixir src and build it. I just git cloned the master repo and built from there.

asdf should work too, but building manually means at least doing

doas zsh
export LANG=en_US.UTF-8
gmake clean test

After that, you have a nice up to date set of binaries in the bin dir. So append this to your PATH

then you end up with

elixir -v
Erlang/OTP 23 [erts-11.1.5] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [dtrace]

Elixir 1.12.0-dev (0792602) (compiled with Erlang/OTP 23)

Yay! Latest !! Very up to date now.

To test it all out

$ mix archive.install hex phx_new 1.5.8
$ mix phx.new hello
$ cd hello

… do the rest, then mix phx.server to run it

Note that localhost:4000 now includes the lovely PhoenixLive Dashboard
Great Success !

This is awesome. Day 1 - I think Im going to enjoy getting into this :wink:

steveoc64

steveoc64

Seems like I was overzealous in pkg install exlixir-*

Tried this

  • remove all elixir packages
  • just install elixir, nothing else using pkg repo (because its only 1 point version off the official release)
  • mix deps.get / deps.compile
    … that works !

So the problem was by the look of it - when I got my first round of issues … I “fixed” them by installing more and more system packages, until I ended up installing everything.

Solution is as above - just install the basic Elixir (preferrably from official latest, but pkg is fine in this case) … the key being to let Hex do the work of adding libs to the project locally.

Thanks all - now I have a working Elixir + Phoenix setup on BSD latest. Happy.

Next trick - writing some NIFS code :slight_smile:

overcomeoj

overcomeoj

Can you use asdf on freebsd? I use that to sort out all my garbage. Tends to be more readily updated than OS level packages.

Where Next?

Popular in Questions Top

JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement