xgeek116
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
Trending in Questions
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
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
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #elixirconf-us
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance












Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
config/config.exsin library codebase is not loaded when used as a dependency.xgeek116
Hi, But I can find it in the installed lib files :
I am missing something?
LostKobrakai
It doesn’t matter if it’s there – config files of your dependencies are not used.
xgeek116
Hi LostKobrakai, So how can I make it work ?
LostKobrakai
You can either move the values into your code or provide app env values (for your app only) via the mix.exs (see vintage_net/mix.exs at main · nerves-networking/vintage_net · GitHub)
xgeek116
The idea is to provide one LIB, but the LIB provide 3 envs (dev, staging and prod) depending on the ENV of the app. How do you think it should be implemented on the LIB side ?
xgeek116
@LostKobrakai how this approche " or provide app env values (for your app only) via the mix.exs "
Can help me get the LIB vars ? you mean I should define the enviromnent in each app that installes the LIB ?
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.
wolf4earth
To add to that, if you decide to rely on the application environment and would still like to rely on some defaults you can do something like the following:
Or a tad more readable:
I do something similar in my
etag_plugpackage.xgeek116
@wolf4earth : Sorry to ask, I’m still beginner but this line will be on the LIB side ?
And this code also ?
When we send the config from the APP to the LIB ?