Hi all
I have a module that looks as follow:

defmodule Cloud.Repo.Seeders.LanguageCode do

  alias Cloud.Repo
  alias Cloud.LanguageCode

  def query_json_file!(filename) do

    case File.read(filemane) do
      {:ok, values} ->
      {:error, reason} ->
        raise reason


  def test() do


Then I want to test on the shell and did as follow:

iex(5)> alias Cloud.Repo.Seeders.LanguageCode
iex(6)> LanguageCode.test
** (UndefinedFunctionError) function Cloud.Repo.Seeders.LanguageCode.test/0 is undefined (module Cloud.Repo.Seeders.LanguageCode is not available)

What am I doing wrong?


1 Like

Did you run iex without arguments?
If your module is in your existing project you need to run iex like that:

iex -S mix

1 Like

Yes I run with
iex -S mix

Somehow, the shell does not recognize the module. And there is no error, when there compile it.

1 Like

Where is the file with code located?

1 Like

It’s your problem:

btw. I don’t know why you don’t have a compilation error.

1 Like

As I was saying, i don’t think the code is being compiled at all. Possibly it is not in the right place.

1 Like

It is a phoenix application. The structure looks as follow:

It is a script file. This module will seed data for db. How can I test the exs file?

iex -S mix does not compile .exs files. You might want to use import_file/1.

# file test.exs
defmodule Test do
  def hello do
$ iex
> import_file "./test.exs"
{:module, Test,
 <<70, 79, 82, 49, 0, 0, 4, 168, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 128,
   131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115,
   95, 118, 49, 108, 0, 0, 0, 4, 104, 2, ...>>, {:hello, 0}}
> Test.hello

Edit: For information on what is compiled on iex -S mix, see the elixirc_paths configuration on mix.exs. Typical Phoenix app should include only lib and web directories. Since your file is on priv, it would not get compiled too. CMIIW.

1 Like

I am so stupid. Thanks so much.

Don’t be so hard on yourself. I only discovered import_file/1 just now too when looking for the answer to your question. We’re all learning here. :slight_smile:

1 Like