Search code examples
elixirphoenix-framework

after deleting`:gettext` in mix.exs file, facing `__hash__` undefined problem


I want to delete the following error message, and have anothe error after deleting :gettext.

warning: the :gettext compiler is no longer required in your mix.exs.

Please find the following line in your mix.exs and remove the :gettext entry:

    compilers: [..., :gettext, ...] ++ Mix.compilers(),

  (gettext 0.20.0) lib/mix/tasks/compile.gettext.ex:5: Mix.Tasks.Compile.Gettext.run/1
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:92: Mix.Tasks.Compile.All.run_compiler/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:72: Mix.Tasks.Compile.All.compile/4
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:59: Mix.Tasks.Compile.All.with_logger_app/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:36: Mix.Tasks.Compile.All.run/1

updat mix.exs as follows:

  def project do
    [
      app: :hello,
      version: "0.1.0",
      elixir: "~> 1.12",
      elixirc_paths: elixirc_paths(Mix.env()),
      # compilers: [:gettext] ++ Mix.compilers(),
      compilers: Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end

  defp deps do
    [
      {:phoenix, "~> 1.6.10"},
      {:phoenix_html, "~> 3.0"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_view, "~> 0.17.5"},
      {:floki, ">= 0.30.0", only: :test},
      {:phoenix_live_dashboard, "~> 0.6"},
      {:esbuild, "~> 0.4", runtime: Mix.env() == :dev},
      {:swoosh, "~> 1.3"},
      {:telemetry_metrics, "~> 0.6"},
      {:telemetry_poller, "~> 1.0"},
      # {:gettext, "~> 0.18"},
      {:jason, "~> 1.2"},
      {:plug_cowboy, "~> 2.5"}
    ]
  end

Following error message appears. How to solve it?

(Debugger) Initialization failed because an exception was raised:
    ** (UndefinedFunctionError) function Gettext.Compiler.__hash__/1 is undefined (module Gettext.Compiler is not available)
        Gettext.Compiler.__hash__("priv/gettext")
        lib/hello_web/gettext.ex:1: HelloWeb.Gettext.__mix_recompile__?/0
        (mix 1.13.4) lib/mix/compilers/elixir.ex:294: anonymous fn/2 in Mix.Compilers.Elixir.compiler_info_from_updated/9
        (elixir 1.13.4) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
        (mix 1.13.4) lib/mix/compilers/elixir.ex:293: Mix.Compilers.Elixir.compiler_info_from_updated/9
        (mix 1.13.4) lib/mix/compilers/elixir.ex:117: Mix.Compilers.Elixir.compile/7
        (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
        (mix 1.13.4) lib/mix/tasks/compile.all.ex:92: Mix.Tasks.Compile.All.run_compiler/2

Solution

  • One should not remove gettext dependency, only the compiler. That said, the following line stays:

    {:gettext, "~> 0.18"},
    

    The compiler provides the additional compilation step, which is not needed anymore, but all the modules and functions defined there are still needed.