Environment variable error

I created an environment variable in config and it works for me but when I run it I get this, does anyone have any idea why it happens?

You have configured application :distributor_public_key in your configuration file,
but the application is not available.

This usually means one of:

  1. You have not added the application as a dependency in a mix.exs file.

  2. You are configuring an application that does not really exist.

Please ensure :distributor_public_key exists or remove the configuration.

Please show your config file.

of course this is the config file

use Mix.Config

config :distributor_public_key,
  public_key: "DISTRIBUTOR_PUBLIC_KEY"

the dev:

use Mix.Config

config :distributor_public_key,
  public_key: "DISTRIBUTOR_PUBLIC_KEY"

the prod

use Mix.Config

config :distributor_public_key,
  public_key: System.get_env("DISTRIBUTOR_PUBLIC_KEY")

Usually You would use the name of your application as the main key…

https://hexdocs.pm/elixir/master/Config.html

Not usually! It is a strict requirement due to how app env works.

When one tries to get app env of an application that is not loaded, the result will be nil.

1 Like

I mean sometime You use the name of the plugin You want to configure… for example waffle. That is why it is not alway the name of the main application.

1 Like

sorry I was wrong in the config I have this:

use Mix.Config

import_config "#{Mix.env()}.exs"

in the dev and the prod if I have them like this

This is what I get

Yes, as we said, the first argument to config/2,3 needs to be an application that is available in the dependency tree.

If you want to configure your toplevel application, use its name, if you want to configure a dependency, use thats name.

what is the name of your application in mix.exs?