mblagusz

mblagusz

Name conflict between internal module and second-level dependency

My application has a widely used internal module named TypedStruct. We recently added a new dependency that depends on the typed_struct package, which also defines TypedStruct. So now when we use TypedStruct, the module in the dependency seems to win.

Do I need to put a prefix on the internal module and adjust all of the use statements, or is there another way to resolve this? I realize that as an internal module it really should have been prefixed to begin with. (We have a few modules like this that were intended as libraries but never made into proper packages.)

As a side note, shouldn’t Elixir give an error when it encounters an ambiguous use statement, rather than just picking one of the modules arbitrarily? I’m on 1.16.

Most Liked

D4no0

D4no0

The rule of thumb is to never define root level modules, each application should use its own based on app name. For example all your modules in your app (if your app is named my_app) should be in format MyApp.*, this is simply because all module names are just atoms and global. The only exceptions you can see with naming is with phoenix, there you have MyApp.* and MyAppWeb.*.

It’s strange that the compiler did not throw an error, because if you would try to define modules with duplicate names in your application, it will not compile.

dimitarvp

dimitarvp

Yes, do that. There are tools that can do it reliably (they don’t rely on regexes) if there are too many instances to comfortably replace by hand. Shout here if you need pointers to them, I’ve used them successfully.

Where Next?

Popular in Questions Top

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
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
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
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
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

We're in Beta

About us Mission Statement