tfwright / live_admin

Low-config admin UI for Phoenix apps, built on LiveView
MIT License
251 stars 22 forks source link

Could not compile: module Docout is not loaded #11

Closed zachallaun closed 1 year ago

zachallaun commented 1 year ago

Hi there!

Trying to give LiveAdmin a try (thanks for making it!), but ran into an issue with Docout. I see it was recently made a dev dependency, which means it's not pulled in when I install from hex, so it's crashing here.

I think the solution is just to wrap that module in Code.ensure_loaded?(Docout).

tfwright commented 1 year ago

Hi @zachallaun

Thanks for the report. Just to be clear, it's crashing when you try to use live_admin in dev? Or other envs as well?

zachallaun commented 1 year ago

It crashes in all envs.

Looking at the docs for publishing on Hex, there are two things preventing Docout from being downloaded by users: 1. it's not a production dependency, and 2. it's a git dependency.

tfwright commented 1 year ago

Yeah it should definitely not need to be downloaded as it is a purely internal dep only used for dev the the library itself, not use of the library in other projects.

I think checking if docout is loaded is a possible way forward but I'd prefer a slightly more explicit solution if possible. I'm thinking maybe requiring a flag to be set in the env vars.

zachallaun commented 1 year ago

Or perhaps the module should live in a support directory that is separate from lib? And then play some games in mix.exs such that it's only included in the elixirc_paths in dev.

def project do
  [
    # ...
    elixirc_paths: elixirc_paths(Mix.env())
  ]
end

defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(:dev), do: ["lib", "support"]
defp elixirc_paths(_), do: ["lib"]
tfwright commented 1 year ago

I don't think that would work because currently I'm using a similar trick to only add docout as a compiler in dev but that is triggered also in the "parent" application's dev environment. AFAIK there is no way to tell within live_admin whether it's being developed as the main app or as a dependency, and so it tries to compile either way (and fails because when added as a hex dep docout is not included).

tfwright commented 1 year ago

Pushed a new version that I think should solve the issue. I actually had to wrap both the compilers and paths in an explicit check. When you get a chance can you try is out and confirm that it solves the issue for you?

https://hex.pm/packages/live_admin/0.5.1

zachallaun commented 1 year ago

Looks like that did the trick! Thanks.

atavistock commented 1 year ago

Yay! I spent hours trying to figure this issue out on main. Found this issue, merged 0.5.1, and its fixed. :+1:

tfwright commented 1 year ago

Oh no! Sorry about that, I thought this issue was fixed on main as well. Were you using the github option in your mix file? Do you happen to know which ref was broken? If it's still an issue I'd definitely like to get it resolved!