elixir-cldr / cldr

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

MyApp.Cldr is either not known or does not appear to be a Cldr backend module #126

Closed AdrianRibao closed 5 years ago

AdrianRibao commented 5 years ago

I have a Phoenix application where I have SetLocale set like this in router.ex

plug Cldr.Plug.SetLocale,
  apps: [:cldr, :gettext],
  cldr: MyApp.Cldr,
  gettext: MyAppWeb.Gettext,
  from: [:query, :path, :body, :cookie, :accept_language]

where:

defmodule MyApp.Cldr do
  use Cldr,
    default_locale: "es",
    locales: ["en", "es"],
    precompile_number_formats: ["¤¤#,##0.##"],
    providers: [Cldr.Number, Cldr.List, Cldr.Unit, Cldr.Territory, Cldr.Language],
    gettext: MyAppWeb.Gettext
end

it works fine on dev, but when I try to compile for production inside a docker container, the compilation fails for router.ex:

** (ArgumentError) MyApp.Cldr is either not known or does not appear to be a Cldr backend module
    (ex_cldr) lib/cldr/plug/plug_set_locale.ex:429: Cldr.Plug.SetLocale.validate_cldr/2
    (ex_cldr) lib/cldr/plug/plug_set_locale.ex:119: Cldr.Plug.SetLocale.init/1
    (plug) lib/plug/builder.ex:302: Plug.Builder.init_module_plug/4
    (plug) lib/plug/builder.ex:286: anonymous fn/5 in Plug.Builder.compile/3
    (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3
    (plug) lib/plug/builder.ex:284: Plug.Builder.compile/3

and in the config I have:

config :my_app, MyAppWeb.Gettext, default_locale: "en", locales: ~w(en es)

config :ex_cldr,
  default_locale: "en",
  json_library: Jason

Am I doing something wrong or maybe there is a bug somewhere?

AdrianRibao commented 5 years ago

More information about this:

This works:

MIX_ENV=dev mix compile

but this fails with the previous error:

MIX_ENV=prod mix compile
AdrianRibao commented 5 years ago

I just found the issue!

Just in case it helps others, it was a wrong path in the template:

<%= Routes.static_path(@conn, "/videos/demo.mp4") %>

It turns out demo.mp4 wasn't available and that made the compilation fail. Commenting that line made it work!

AdrianRibao commented 5 years ago

Sorry, unfortunately that wasn't the problem, I had removed the plug comment accidentally, and that's why I didn't get the error... So back to square one.

kipcole9 commented 5 years ago

@AdrianRibao Apologies for now being responsive on this. Still an issue for you I assume? I can only think of it as a compilation order issue and I'm finding it hard to reproduce.

kipcole9 commented 5 years ago

I think this may have been similar to issue #124 and I have applied the same "fix" with this commit. I will close this issue for now but of course please reopen it if my assumption is incorrect.

AdrianRibao commented 5 years ago

@kipcole9 I ended up using my own plug because I couldn't use this package. I'll try to use the latest version when it's released, and check if it's fixed.

Thanks!

kipcole9 commented 5 years ago

Totally understand and I'm sorry I let you down (in fact somehow I didn't even see you had reopened the issue although thats not an excuse).

The new version is on hex now as ex_cldr version 2.7.2.

ghost commented 4 years ago

@kipcole9 Hi! Just to let you know, I'm getting the same error as in OP in the latest version. dev env compiles fine, but then in test env SetLocale plug fails to validate the cldr module.

kipcole9 commented 4 years ago

@syfgkjasdkn Do you have a test case I can work on? Or at least an example you're trying that is failing? Please also open a new issue - this issue was related to compilation ordering.