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
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex












First 10 of 16 Posts
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 ?