Creating a Custom MIX_ENV (not dev, test or prod)

I am trying to set up a 4th environment besides the default dev, test and prod - demo. I created a config/demo.exs . But when I run MIX_ENV=demo, I get the following error. Because I do not see the error in any of the other environments, I think it has something to do with how I set up the demo environment. Are there steps to creating a custom environment that I am missing? Thank you.

 Compilation error in file lib/<app_name>/endpoint.ex ==
** (UndefinedFunctionError) function Phoenix.LiveReloader.init/1 is undefined (module Phoenix.LiveReloader is not available)
    Phoenix.LiveReloader.init([])
    (plug) lib/plug/builder.ex:193: Plug.Builder.init_module_plug/3
    (plug) lib/plug/builder.ex:181: anonymous fn/4 in Plug.Builder.compile/3
    (elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
    (plug) lib/plug/builder.ex:181: Plug.Builder.compile/3
    (plug) expanding macro: Plug.Builder.__before_compile__/1
    lib/<app_name>/endpoint.ex:1: APPNAME.Endpoint (module)
    (elixir) lib/kernel/parallel_compiler.ex:198: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

You have enabled live reload in your configuration (config/demo.exs), but the necessary dependency is (probably) only: :dev in mix.exs.

You need to change the dep to {:phoenix_live_reload, …, only: [:dev, :demo]} or remove the live reload config for that environment.

But in general, simply simply setting MIX_ENV creates arbitrary environments, of course you need to make sure you get your config/dependencies right.

3 Likes

Thank you that fixed my problem!