How to get gleam standard library to work in a mix project

I have followed this guide on adding Gleam to an Elixir project.
I’ve tweaked it somewhat as I am adding to a pure Elixir project, no phoenix.

Gleam code written in my project works but I am not able to get any gleam libraries to work.
This unfortunately includes the Gleam standard library.

I suspect there is some mix option that says I need to use the compilers for the libraries, but can’t work it out.

Here is the exact version of the code I am trying to run https://github.com/midas-framework/elixir_with_gleam
Running mix compile gives the following error.

error: Unknown import

   ┌── /opt/app/src/hello.gleam:1:8 ───
   │
 1 │ import gleam/string
   │        ^^^^^^^^^^^^ did you mean `hello`?
   │

The module `hello` is trying to import the module `gleam/string`,
but it cannot be found.
1 Like

I got it working.
Here is an example project.

5 Likes

Thanks for this, super cool!

I’ve packaged up this idea into a tiny library to make it easier to use Gleam from Elixir in future -> https://github.com/gleam-lang/mix_gleam/

2 Likes

Great.

I’ve also updated https://github.com/midas-framework/elixir_with_gleam to reflect the changes

1 Like