xgeek116

xgeek116

Using a custom Elixir Library that uses Env variables

I created a test elixir lib that uses a file config/config.exs to store env variables for example :

config.exs :

import Config

url_dev = "DEV"
url_prod = "PROD"

config :test_lib,
  dev: [
    url: url_dev,
  ],
  production: [
    url: url_prod,
  ]

and in the lib/test_lib_elixir_package.exs, I called tha variable :

defmodule TestLibElixirPackage do
  def testFunction do
    dev_url = Application.fetch_env!(:test_lib, :dev)
    dev_url[:url]
  end
end

When I test the lib with IEX i can obtain the result of the function testFunction

But When I installed the LIB in an elixir app and tried to call the function I got this error :

“** (ArgumentError) could not fetch application environment :dev for application :test_lib because the application was not loaded nor configured
(elixir 1.13.1) lib/application.ex:683: Application.fetch_env!/2
(test_lib_elixir_package 0.1.2) lib/test_lib_elixir_package.ex:8: TestLibElixirPackage.testFunction/0”

Here is my mix.exs from the library (I included the config directory) :

defp package do
    [
      files: ["lib", "config", "mix.exs", "README*"],
      description: "Testing build and publish elixir lib",
      maintainers: ["test"],
      licenses: ["MIT"],
      links: %{}
    ]
  end

Most Liked

hauleth

hauleth

config/config.exs in library codebase is not loaded when used as a dependency.

LostKobrakai

LostKobrakai

It doesn’t matter if it’s there – config files of your dependencies are not used.

hauleth

hauleth

Ideally you should not use the application environment in libraries at all. But answering your question - yes, you should define configuration each time you use dependency.

xgeek116

xgeek116

Hi, But I can find it in the installed lib files :

I am missing something?

xgeek116

xgeek116

Hi LostKobrakai, So how can I make it work ?

Where Next?

Popular in Questions Top

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New

We're in Beta

About us Mission Statement