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

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
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
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
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New

We're in Beta

About us Mission Statement