Phoenix v1.3 API tutorial compilation error

Trying to learn how to build an API with Phoenix v1.3
following this tutorial: https://dreamconception.com/tech/phoenix-full-fledged-api-in-five-minutes (made sure to follow each step to the letter)

When I attempt to run mix ecto.setup

I get the following error:

Compiling 17 files (.ex)

== Compilation error on file lib/myapp/users/users.ex ==
** (CompileError) lib/myapp/users/users.ex:65: Myapp.Users.User.__struct__/0 is undefined, cannot expand struct Myapp.Users.User
    (stdlib) lists.erl:1354: :lists.mapfoldl/3
    lib/myapp/users/users.ex:65: (module)
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

This is the code: GitHub - nelsonic/phoenix-api-example: Phoenix v1.3 API Example using Coherence

Any help debugging it would be much appreciated.

The error indicates where to look at

line 65 of file lib/myapp/users/users.ex

That seems already strange not to use user.ex for the name of file.

Please show us the file, it might be a typo

Hi @kokolegorille thanks for quick reply. all the code is on GitHub.
the specific file you are requesting is: https://github.com/nelsonic/phoenix-api-example/blob/master/lib/myapp/users/users.ex
Note: the users.ex file was auto-generated not named by me.

Do you actually have a Myapp.Users.User struct somewhere? The thing you linked just defined a Myapp.Users module, and no structs.

There is a typo in the generated code

defmodule Myapp.Users do
  @moduledoc """
  The boundary for the Users system.
  """

  import Ecto.Query, warn: false
  alias Myapp.Repo

alias Myapp.Users.User

It should be defmodule Myapp.Users.User

try changing this, maybe :slight_smile:

my bet is You made a typo when typing this

mix coherence.install --full-confirmable --model=“Users.User users”

when following tuto

I copy-pasted all the commands form the tutorial. didn’t type anything, so if anything there might be a typo in the original post … :confounded:

I attempted to change defmodule Myapp.Users do to defmodule Myapp.Users.User the error is unchanged. :persevere:

Since the tutorial is using development branches this was bound to happen. I’ve corrected the tutorial and created a repo for the source code on Github: https://github.com/danschultzer/phoenix_ex_oauth2_provider_demo

2 Likes