elixir-cldr / cldr

Elixir implementation of CLDR/ICU
Other
447 stars 33 forks source link

Cldr.UnknownBackendError) The backend Demo.Cldr is not known or not a backend module #135

Closed ghost closed 4 years ago

ghost commented 4 years ago

Repro: https://github.com/syfgkjasdkn/cldr-demo

Continued from https://github.com/elixir-cldr/cldr/issues/126

mix compile works fine, but MIX_ENV=test mix compile fails with

==> demo
Compiling 16 files (.ex)

== Compilation error in file lib/demo_web/router.ex ==
** (Cldr.UnknownBackendError) The backend Demo.Cldr is not known or not a backend module.
    lib/cldr/plug/plug_set_locale.ex:426: Cldr.Plug.SetLocale.validate_cldr/2
    lib/cldr/plug/plug_set_locale.ex:119: Cldr.Plug.SetLocale.init/1
    (plug 1.10.1) lib/plug/builder.ex:304: Plug.Builder.init_module_plug/4
    (plug 1.10.1) lib/plug/builder.ex:288: anonymous fn/5 in Plug.Builder.compile/3
    (elixir 1.10.3) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
    (plug 1.10.1) lib/plug/builder.ex:286: Plug.Builder.compile/3
    lib/demo_web/router.ex:16: (module)
kipcole9 commented 4 years ago

Really appreciate the repo, thank you, will work on this tonight (evening coming up in my timezone)

kipcole9 commented 4 years ago

I suspect the the compiler isn't picking up the module dependency. So while I work on this may I suggest you try adding require Demo.Web to the top of lib/demo_web/router.ex? That will force the compiler to compile Demo.Web first.

The difference is that in :dev mode, Plug.init/1 is called lazily at runtime. In :prod and I assume :test it is called at compile time. Therefore Demo.Cldr needs to be compiled before the router compilation and the compiler isn't detecting that dependency.

kipcole9 commented 4 years ago

Validated. In router.ex:

defmodule DemoWeb.Router do
  use DemoWeb, :router

  # Adding the require forces the compiler 
  # to process this module now
  require Demo.Cldr

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    ...

Then compile:

kip@Kips-iMac-Pro cldr-demo % MIX_ENV=test mix compile
Compiling 16 files (.ex)

16:56:00.929 [info]  Downloaded locale "de"
Generating Demo.Cldr for 4 locales named ["de", "en", "en-001", "root"] with a default locale named "de"
Generated demo app

I'm not sure why the compiler isn't identifying the dependency earlier. Will investigate.

kipcole9 commented 4 years ago

I have submitted this issue.

kipcole9 commented 4 years ago

On Josés advice I've take another route that does not require changing your code. It is now on hex as ex_cldr version 2.14.1. The changelog entry is:

Bug Fixes

Upgrading

% mix deps.update ex_cldr
% MIX_ENV=test mix compile

All should be good now. I will close this issue, let me know if you see other issues. And thanks for the report.

ghost commented 4 years ago

@kipcole9 thank you!

petermm commented 4 years ago

fwiw I had issue https://github.com/elixir-cldr/cldr/issues/126 on 2.14.0 and needed to move/copy the MyApp.Cldr module into the top of the router.ex file to compile in prod (leading to slow recompile issues in dev..)

2.14.1 fixed it🎉

kipcole9 commented 4 years ago

@petermm, happy to hear it helped you too! Please don't hesitate to file an issue any time if something seems awry. I try hard to be responsive and fix bugs. I hate bugs. And I don't want there to be a poor experience using these libs.

seb3s commented 3 years ago

Hello, I had the same issue as reported by one of my user of Kandesk https://github.com/seb3s/kandesk/issues/4 I tried upgrading to the latest version but it still fails cldr_utils 2.14.0 ex_cldr 2.18.2 ex_cldr_calendars 1.12.0 ex_cldr_currencies 2.8.0 ex_cldr_dates_times 2.6.3 ex_cldr_numbers 2.16.1

I put some logger and see I get 14:01:53.264 [info] Module Elixir.KandeskWeb.Cldr, Cldr error: :unavailable which https://hexdocs.pm/elixir/Code.html#ensure_compiled/1 indicates is a deadlock compilation.

My config : Erlang/OTP 22 [erts-10.7] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe] Interactive Elixir (1.10.0) - press Ctrl+C to exit (type h() ENTER for help)

Maybe I did something wrong in the configuration. All code is currently available at kandesk. Hope this helps

Sébastien.