odohMei7
Dependency error: Phoenix with gun
I am new to phoenix and want to use it with gun to subscribe to websockets. But when I try this in a phoenix project, I get a dependency error. As a minimal example do the following:
$ mix phx.new --version
Phoenix v1.5.3
$ mix phx.new test --no-ecto
[...]
Then I add gun to the dependencies:
defp deps do
[
{:phoenix, "~> 1.5.3"},
{:phoenix_html, "~> 2.11"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_dashboard, "~> 0.2.0"},
{:telemetry_metrics, "~> 0.4"},
{:telemetry_poller, "~> 0.4"},
{:gettext, "~> 0.11"},
{:jason, "~> 1.0"},
{:plug_cowboy, "~> 2.0"},
{:gun, "~> 1.3.2"},
]
end
But when I do mix deps.get I get the following error:
Resolving Hex dependencies...
Failed to use "cowlib" because
gun (version 1.3.2) requires ~> 2.6.0
mix.lock specifies 2.9.1
** (Mix) Hex dependency resolution failed, change the version requirements of your dependencies or unlock them (by using mix deps.update or mix deps.unlock). If you are unable to resolve the conflicts you can try overriding with {:dependency, "~> 1.0", override: true}
What should I do? Thanks in advance.
Marked As Solved
benwilson512
No, that is not possible, Elixir can only load one version of code for a given application. However you may be in luck, it looks like the version of gun on github supports the latest cowlib. You could try doing:
{:gun, github: "ninenines/gun"},
Also Liked
LostKobrakai
This is not a bug. You installed phoenix, which then fetched the latest version of cowlib and locks the version in mix.lock (this happens for all your dependencies). gun however needs an earlier version of cowlib. You’re however unlikely to be using cowlib directly (transitive dependency) and it seems non of your direct dependencies actually conflicts with the version constraint of gun, so you should be able to safely do mix deps.unlock cowlib, mix deps.get. This will remove the lock on the currently installed version of cowlib and allow mix to resolve the selected version under those new constraints with gun.
LostKobrakai
axelson
I’m pretty sure that would only happen if you don’t commit your mix.lock file which you almost always should commit for elixir projects.
Last Post!
benwilson512
I think this is a perfectly fine stance to take, I just wanted to make sure that the OP was clear on how mix.lock works.
Popular in Questions
Other popular topics
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
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex










