Question about a strange error in VSCode using ElixirLS, Cldr and Phoenix

I am using Cldr in my phoenix project, which just works flawlessly. I also run credo and dialyxir on the code base. No problems at all. But I get in vscode the following error.

(Cldr.UnknownBackendError) The backend Jocasta.Cldr is not known or not a backend module.

  │ (ex_cldr 2.18.2) lib/cldr.ex:547: Cldr.validate_backend!/1
  │ (ex_cldr 2.18.2) lib/cldr/plug/plug_set_locale.ex:363: Cldr.Plug.SetLocale.validate_app_and_scope!/2
  │ (ex_cldr 2.18.2) lib/cldr/plug/plug_set_locale.ex:331: anonymous fn/1 in Cldr.Plug.SetLocale.validate_apps/2
  │ (elixir 1.11.3) lib/enum.ex:1411: Enum."-map/2-lists^map/1-0-"/2
  │ (ex_cldr 2.18.2) lib/cldr/plug/plug_set_locale.ex:329: Cldr.Plug.SetLocale.validate_apps/2
  │ (ex_cldr 2.18.2) lib/cldr/plug/plug_set_locale.ex:172: Cldr.Plug.SetLocale.init/1
  │ (plug 1.11.0) lib/plug/builder.ex:304: Plug.Builder.init_module_plug/4
  │ (plug 1.11.0) lib/plug/builder.ex:288: anonymous fn/5 in Plug.Builder.compile/3

This error shows up as soon as I add this plug to the browser pipeline in router.ex.

    plug Cldr.Plug.SetLocale,
      apps: [cldr: Jocasta.Cldr, gettext: Jocasta.Gettext],
      from: [:accept_language]

Where Jocasta.Cldr looks like that.

defmodule Jocasta.Cldr do
  use Cldr,
    gettext: Jocasta.Gettext,
    providers: [Cldr.Number, Cldr.List, Cldr.Calendar, Cldr.DateTime]

When I validate the module in iex, I get no errors either.

iex(1)> Cldr.validate_backend(Jocasta.Cldr)
{:ok, Jocasta.Cldr}

Any hints how I can get rid of the error in vscode?

@kip suggests adding something like the following code to the router.ex to fix a compilation error.

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

It doesn’t seem to be necessary as of ex_cldr 2.14.1, but it sees to be necessary in the VSCode + ElixirLS context.

1 Like