jerry

jerry

I am running Elixir 1.14 on my machine.
I have a config folder with runtime.exs, runtime.prod.exs, and runtime.dev.exs
I reference environment variables inside runtime.prod.exs and runtime.dev.exs.

Things seem to work well in development environment, but things begin to fail when I deploy into production.
The environment variables are not seen, although this is not the case in development environment.

I have tried to revert to config.exs, prod.exs, and dev.exs.
But that is also not working.

Below is a sample error when I attempt to run the application in production:

** (EXIT) an exception was raised:
** (ArgumentError) could not fetch application environment :host_port for application :my_app because configuration at :host_port was not set

Can I get some help on how I should go about the configuration?

Thank you.

Showing Posts 1 to 9

dimitarvp

dimitarvp

Can you post some excerpts from your config?

But I’m thinking it’s likely that some of your config is taken from env vars at compile time.

jerry

jerry OP

I got this, runtime.exs, code from one of the sites:

##runtime.exs
import Config

case config_env() do
  :dev ->
        Code.require_file("runtime.dev.exs", "config")
  :prod ->
        Code.require_file("runtime.prod.exs", "config")
end

##runtime.dev.exs
config :my_app,
	host_port: String.to_integer(System.fetch_env!("APP_PORT"))

##runtime.prod.exs
config:
       host_port: String.to_integer(System.fetch_env!("APP_PORT"))

runtime.dev.exs works fine, but runtime.prod.exs does not.

Inside my application.ex file/module, I have this:

defmodule MyApp.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

  def start(_type, _args) do
    port=Application.fetch_env!(:my_app, :host_port)

    # List all child processes to be supervised
    children = [
      
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

The error I get is:
** (EXIT) an exception was raised:
** (ArgumentError) could not fetch application environment :host_port for application :my_app because configuration at :host_port was not set

dimitarvp

dimitarvp

Good, now maybe also try formatting them properly – with triple backticks (```) at the start and end of each block. :sweat_smile:

jerry

jerry OP

Which block, please?

I seem a little lost… :smiley:

dimitarvp

dimitarvp

The code blocks that you pasted. Surround them with triple backticks – ``` – on the line before and the line after the block. Like so:

defmodule Hello do
  def there(), do: "General Kenobi!"
end

This has triple backticks before the first line and after the last line.

derek-zhou

derek-zhou

How did you set the environment variables in production? If your runtime.exs does not see them then they were not there. Whatever ways you used to set them must have not worked.

Nicd

Nicd

In that case it would crash at the System.fetch_env! call.

This syntax doesn’t look correct.

kokolegorille

kokolegorille

I made the change for You this time, so You can see your post with format… like in Markdown.

jerry

jerry OP

Thanks to you all for your comments and suggestions.

I have been able to get the configurations to work now.
There was a wrong naming of the environment, prod, and so the environment variables were not being seen.

Does it mean the environment cannot change from dev or prod to any other name or even an additional environment added such as a staging environment, stag?

I am grateful to you all.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews