question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Struct undefined, cannot expand struct

See original GitHub issue

Hello there!

I have two modules defined in different files, one is using the struct defined in the other, as the following code explains:

# ./lib/identicon.ex

defmodule Identicon do
  def hash_input(input) do
    hex = :crypto.hash(:md5, input)
      |> :binary.bin_to_list()
    # I'm getting the error in the line below
    %Identicon.Image{hex: hex}
  end
end
# ./lib/image.ex

defmodule Identicon.Image do
  defstruct hex: nil, color: nil, grid: nil, pixel_map: nil
end

The exact error I get from elixirlinter is the following: Error: Identicon.Image.__struct__/0 is undefined, cannot expand struct Identicon.Image

The application is running perfectly when executed using iex -S mix.

It seems that I can’t load external dependencies for the current file. My question is how to do that? Is there any better approach?

Thanks in advance!

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:6
  • Comments:9

github_iconTop GitHub Comments

1reaction
Yonbencommented, Jan 17, 2017

+1 here, I’m following the same course and have the same issue.

0reactions
gus4nocommented, Sep 26, 2020

Has anyone found a solution to this? I’m following the same course and have the exact same issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot expand struct - elixir/phoenix - Stack Overflow
__struct__/1 is undefined, cannot expand struct Locations . BTW I'm new to elixir so I'm probably doing something really obvious wrong.
Read more >
Questions / Help - Elixir Forum
Hi all I have following struct definition: @enforce_keys [:uri, :user, ... Worker.__struct__/0 is undefined, cannot expand struct Worker.
Read more >
Today I Learned: Aliasing an Elixir Module Within Itself
__struct__/0 is undefined, cannot expand struct Post. The issue was in a function I defined in the module. def changeset(%Post{}= post, ...
Read more >
Introduction to Mix - Joy of Elixir
__struct__/0 is undefined, cannot expand struct Person. ... This error is occurring because Elixir cannot find a module called Person anymore.
Read more >
Problem placing helper .ex files into test directory. Somehow ...
__struct__/0 is undefined, cannot expand struct TestRuntimeCtx. (elixir) src/elixir_map.erl:44: :elixir_map.translate_struct/4.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found