Phoenix: Could not compile dependency :ranch

Background

I have created a project using mix phx.new my_app --no-ecto and everything looked fine. However I am not able to run the created project.

Error

When I execute mix phx.server (after running mix deps.get)I get the following error:

===> Compiling ranch
===> Command ' OTP' not found in namespace bare
** (Mix) Could not compile dependency :ranch, "/home/user/.asdf/installs/elixir/1.7.3-otp-21/.mix/rebar3 bare compile --paths "/home/user/Workspace/exercises/islands_interface/_build/dev/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile ranch", update it with "mix deps.update ranch" or clean it with "mix deps.clean ranch"

OS and Language Info

Distributor ID:	Ubuntu
Description:	Ubuntu 19.04
Release:	19.04
Codename:	disco

elixir         1.7.3-otp-21
erlang         21.1    

Actions taken

To discard the possibility of this being a temporary issue I also ran mix local.rebar and then rm -rf _build/ but to no avail.

I have also made a search online and found this rebar issue, but I am not sure if and how this correlates to the problem I have at hand: github.com/elixir-lang/elixir/issues/4970

How can I fix this?

Stack Overflow discussion


FYI: just tried this and ranch compiles without error:

$ docker pull ubuntu:19.04
$ docker run -ti --rm ubuntu:19.04 /bin/bash
# cat /etc/lsb-release
# apt update
# apt install git
# git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.7.2
# echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.bashrc
# echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
# . ~/.bashrc
# apt-get -y install build-essential autoconf m4 libncurses5-dev libwxgtk3.0-dev libgl1-mesa-dev libglu1-mesa-dev libpng-dev libssh-dev unixodbc-dev xsltproc fop
# asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git
# asdf install erlang 21.1
# mkdir test
# cd test
# asdf local erlang 21.1
# cd ..
# asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git
# asdf install elixir 1.7.3-otp-21
# cd test
# asdf local elixir 1.7.3-otp-21
# mix local.hex
# mix archive.install hex phx_new 1.4.6
# mix phx.new my_app --no-ecto
# cd my_app
# mix phx.server

To become functional the above is still missing:

  • setting to a UTF-8 locale (default is POSIX)
  • installing node.js

But at least it doesn’t seem to be some Ubuntu 19.04 weirdness.

I do find the leading space in Command ’ OTP’ not found a bit strange but I have no idea where that comes from.

Yea… it looks like rebar3 is saying it failed to run the command rebar3 bare OTP. No idea where that would be coming from.

It fails when running the command mix archive.install hex phx_new 1.4.6.

Resolving Hex dependencies...
Dependency resolution completed:
New:
  phx_new 1.4.6
* Getting phx_new (Hex package)
All dependencies up to date
Compiling 10 files (.ex)
warning: redefining module Mix.Tasks.Local.Phx (current version loaded from /home/admanmedia/.asdf/installs/elixir/1.7.3-otp-21/.mix/archives/phx_new-1.4.1/phx_new-1.4.1/ebin/Elixir.Mix.Tasks.Local.Phx.beam)
  lib/mix/tasks/local.phx.ex:1

warning: redefining module Mix.Tasks.Phx.New.Ecto (current version loaded from /home/admanmedia/.asdf/installs/elixir/1.7.3-otp-21/.mix/archives/phx_new-1.4.1/phx_new-1.4.1/ebin/Elixir.Mix.Tasks.Phx.New.Ecto.beam)
  lib/mix/tasks/phx.new.ecto.ex:1

warning: redefining module Mix.Tasks.Phx.New.Web (current version loaded from /home/admanmedia/.asdf/installs/elixir/1.7.3-otp-21/.mix/archives/phx_new-1.4.1/phx_new-1.4.1/ebin/Elixir.Mix.Tasks.Phx.New.Web.beam)
  lib/mix/tasks/phx.new.web.ex:1

warning: redefining module Mix.Tasks.Phx.New (current version loaded from /home/admanmedia/.asdf/installs/elixir/1.7.3-otp-21/.mix/archives/phx_new-1.4.1/phx_new-1.4.1/ebin/Elixir.Mix.Tasks.Phx.New.beam)
  lib/mix/tasks/phx.new.ex:1

warning: redefining module Phx.New.Ecto (current version loaded from /home/admanmedia/.asdf/installs/elixir/1.7.3-otp-21/.mix/archives/phx_new-1.4.1/phx_new-1.4.1/ebin/Elixir.Phx.New.Ecto.beam)
  lib/phx_new/ecto.ex:1

warning: redefining module Phx.New.Project (current version loaded from /home/admanmedia/.asdf/installs/elixir/1.7.3-otp-21/.mix/archives/phx_new-1.4.1/phx_new-1.4.1/ebin/Elixir.Phx.New.Project.beam)
  lib/phx_new/project.ex:1

warning: redefining module Phx.New.Generator (current version loaded from /home/admanmedia/.asdf/installs/elixir/1.7.3-otp-21/.mix/archives/phx_new-1.4.1/phx_new-1.4.1/ebin/Elixir.Phx.New.Generator.beam)
  lib/phx_new/generator.ex:1


== Compilation error in file lib/phx_new/ecto.ex ==
** (File.Error) could not read file "/tmp/mix-local-installer-fetcher-INAwqA/deps/phx_new/templates/phx_umbrella/apps/app_name/config/config.exs": no such file or directory
    (elixir) lib/file.ex:319: File.read!/1
    lib/phx_new/generator.ex:30: anonymous fn/4 in Phx.New.Generator."MACRO-__before_compile__"/2
    (elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/phx_new/generator.ex:26: anonymous fn/3 in Phx.New.Generator."MACRO-__before_compile__"/2
    (elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
    expanding macro: Phx.New.Generator.__before_compile__/1
    lib/phx_new/ecto.ex:1: Phx.New.Ecto (module)

I am out of ideas by now …

There are the usual suspects:

$ mix archive
  * hex-0.19.0
  * phx_new-1.4.6
$ mix archive.uninstall phx_new-1.4.6
$ mix archive.uninstall hex-0.19.0
$ mix archive
  No archives currently installed.
$ mix local.hex
$ mix archive.install hex phx_new 1.4.6

I presume this trouble only started once you tried to do anything with Phoenix?

Before that you had been using Elixir/Mix on this installation for a while?

How did you know to install all that stuff?

Various sources. e.g.:

I should have trimmed the GUI libs and included apt-utils, locales and inotify-tools.

Basically experiment and adjust when something is missing …

The issues started once I started trying to use Phoenix via the mix phx.server command.
This is a fresh project created with mix phx.new my_app_name --no-ecto. Running mix deps.get and any other mix command works without issue.

I have also run the commands you specified, but the issue remains the same.

have you tried mix deps.clean --all and then mix deps.get ?

1 Like

Yes, the error remains.

I just found out what the error was.

Upon reviewing this comment it got me thinking …

This is the absolute path of the project:

/home/user/Workspace/Functional Web Development with Elixir, OTP, and Phoenix/islands_interface

Turns out, phx.server errors out because it is inside the folder Functional Web Development with Elixir, OTP, and Phoenix/. Turns out that space in ’ OTP’ is from the folder’s name.

To prove my theory I created a project called test under /home/user/Workspace/. Everything worked perfectly.
This proves that the issue here is the path, more specifically, the folder’s name. The conclusion I draw from here is that you can’t have a folder whose name has spaces and with the word “OTP” in it, or else rebar (and for some reason, ranch) won’t work.

Is this a bug? Should I report this behavior somewhere?

1 Like

Technically yes, as white space is allowed in file paths.

But whitespace has historically created nothing but trouble (having to quote file paths on the command line to begin with) so people, myself included, simply avoid it.

How and where should I report this?

The simplest would be to simply report it on the Phoenix repository.

That said, I suspect it will migrate to Elixir because it revolves around mix/rebar.

  • I’m not sure that lib_path will have quoted paths (which is necessary if the path contains whitespace)
  • I don’t know if rebar/rebar3 handle quoted paths
1 Like

Phoenix Issues page specifically states I should not post a bug report there when said bug comes from Elixir or from one of Phoenix’s dependencies. I have therefore created an issue in Elixir’s page pointing to this discussion and to StackOverflow.

1 Like

Seems Elixir/Mix is doing it’s job - on mac os:

$ mkdir "Functional Web Development with Elixir, OTP, and Phoenix"
$ cd "Functional Web Development with Elixir, OTP, and Phoenix"
$ mix phx.new hello --no-ecto
$ cd hello
$ mix phx.server
===> Compiling ranch
===> Command ' OTP' not found in namespace bare
** (Mix) Could not compile dependency :ranch, "/Users/dev/.mix/rebar3 bare compile --paths "/Users/dev/sbox/phx/Functional Web Development with Elixir, OTP, and Phoenix/hello/_build/dev/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile ranch", update it with "mix deps.update ranch" or clean it with "mix deps.clean ranch"
$ 

  • It’s commas that cause the problem (not whitespace)
  • It’s a rebar3 issue.
$ mkdir "key,value"
$ cd "key,value"
$ mix phx.new hello --no-ecto
$ cd hello
$ mix phx.server
===> Compiling ranch
===> Command 'value/hello/_build/dev/lib/*/ebin' not found in namespace bare
** (Mix) Could not compile dependency :ranch, "/Users/dev/.mix/rebar3 bare compile --paths "/Users/dev/sbox/phx/key,value/hello/_build/dev/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile ranch", update it with "mix deps.update ranch" or clean it with "mix deps.clean ranch"
$ rebar3 bare compile --paths "/Users/dev/sbox/phx/key,value/hello/_build/dev/lib/*/ebin"
===> Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace or consult rebar3.crashdump
===> When submitting a bug report, please include the output of `rebar3 report "your command"`
$ rebar3 report "bare compile --paths "/Users/dev/sbox/phx/key,value/hello/_build/dev/lib/*/ebin" report"
Rebar3 report
 version 3.3.5+build.3719.ref4725d36
 generated at 2019-06-06T13:31:14+00:00
=================
Please submit this along with your issue at https://github.com/erlang/rebar3/issues (and feel free to edit out private information, if any)
-----------------
Task: bare
Entered as:
  bare compile --paths /Users/dev/sbox/phx/key,value/hello/_build/dev/lib/*/ebin report
-----------------
Operating System: x86_64-apple-darwin18.5.0
ERTS: Erlang/OTP 21 [erts-10.3.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:0] [hipe] [dtrace]
Root Directory: /usr/local/Cellar/erlang/21.3.7/lib/erlang
Library directory: /usr/local/Cellar/erlang/21.3.7/lib/erlang/lib
-----------------
Loaded Applications:
bbmustache: 1.3.0
certifi: 0.4.0
cf: 0.2.2
common_test: 1.17.1
compiler: 7.3.2
crypto: 4.4.2
cth_readable: 1.2.3
dialyzer: 3.3.2
edoc: 0.10
erlware_commons: 1.0.0
eunit: 2.3.7
eunit_formatters: 0.3.1
getopt: 0.8.2
inets: 7.0.7
kernel: 6.3.1
providers: 1.6.0
public_key: 1.6.5
relx: 3.22.2
sasl: 3.3
snmp: 5.2.12
ssl_verify_fun: 1.1.1
stdlib: 3.8.1
syntax_tools: 2.1.7
tools: 3.1

-----------------
Escript path: /usr/local/bin/rebar3
Providers:
  app_discovery as clean compile compile cover ct deps dialyzer do edoc escriptize eunit get-deps help install install_deps list lock new path pkgs release relup report shell state tar tree unlock update upgrade upgrade upgrade version xref 
$ export DEBUG=1
$ rebar3 bare compile --paths "/Users/dev/sbox/phx/key,value/hello/_build/dev/lib/*/ebin"
===> Expanded command sequence to be run: []
===> Expanded command sequence to be run: [{default,app_discovery},
                                                  {bare,compile}]
===> Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace or consult rebar3.crashdump
===> Uncaught error: {badmatch,[]}
===> Stack trace to the error location:
[{rebar_prv_bare_compile,do,1,
                         [{file,"/Users/dev/sbox/erl/rb/rebar3/_build/default/lib/rebar/src/rebar_prv_bare_compile.erl"},
                          {line,45}]},
 {rebar_core,do,2,
             [{file,"/Users/dev/sbox/erl/rb/rebar3/_build/default/lib/rebar/src/rebar_core.erl"},
              {line,153}]},
 {rebar_prv_do,do_tasks,2,
               [{file,"/Users/dev/sbox/erl/rb/rebar3/_build/default/lib/rebar/src/rebar_prv_do.erl"},
                {line,68}]},
 {rebar_core,do,2,
             [{file,"/Users/dev/sbox/erl/rb/rebar3/_build/default/lib/rebar/src/rebar_core.erl"},
              {line,153}]},
 {rebar3,main,1,
         [{file,"/Users/dev/sbox/erl/rb/rebar3/_build/default/lib/rebar/src/rebar3.erl"},
          {line,66}]},
 {escript,run,2,[{file,"escript.erl"},{line,758}]},
 {escript,start,1,[{file,"escript.erl"},{line,277}]},
 {init,start_em,1,[]}]
===> When submitting a bug report, please include the output of `rebar3 report "your command"`
$

You should probably gather and submit similar information for your Ubuntu 19.04 platform.

1 Like

Hah, nice, good find @peerreynders. Please get a ticket open on rebar3.

1 Like

@peerreynders You did all of the work of finding out what the issue was. To add to that, I am still learning how to improve my communication skills with the maintainer of the rebar3 project, so I think it’s best for everyone if I leave the honors of filing the bug to you.

Here is the information you asked about my system:

$ export DEBUG=1
$ ./rebar3 report "bare compile --paths "/home/user/Workspace/key,value/hello/_build/dev/lib/*/ebin" report"
===> Expanded command sequence to be run: [{default,report}]
===> Provider: {default,report}
Rebar3 report
 version 3.11.1
 generated at 2019-06-06T14:37:37+00:00
=================
Please submit this along with your issue at https://github.com/erlang/rebar3/issues (and feel free to edit out private information, if any)
-----------------
Task: bare
Entered as:
  bare compile --paths /home/user/Workspace/key,value/hello/_build/dev/lib/*/ebin report
-----------------
Operating System: x86_64-unknown-linux-gnu
ERTS: Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Root Directory: /home/user/.asdf/installs/erlang/21.1
Library directory: /home/user/.asdf/installs/erlang/21.1/lib
-----------------
Loaded Applications:
bbmustache: 1.6.1
certifi: 2.5.1
cf: 0.2.2
common_test: 1.16.1
compiler: 7.2.5
crypto: 4.3.3
cth_readable: 1.4.4
dialyzer: 3.3.1
edoc: 0.9.4
erlware_commons: 1.3.1
eunit: 2.3.7
eunit_formatters: 0.5.0
getopt: 1.0.1
hipe: 3.18.1
inets: 7.0.2
kernel: 6.1
providers: 1.8.1
public_key: 1.6.2
relx: 3.32.1
sasl: 3.2.1
snmp: 5.2.12
ssl_verify_fun: 1.1.5
stdlib: 3.6
syntax_tools: 2.1.6
tools: 3.0.1

-----------------
Escript path: /home/user/Workspace/key,value/hello/rebar3
Providers:
  app_discovery as clean compile compile cover ct deps dialyzer do edoc escriptize eunit get-deps help install install_deps list lock new path pkgs release relup report repos shell state tar tree unlock update upgrade upgrade upgrade version xref

I have followed exactly your footsteps. I hope that adding this information to your report will help somehow.

As requested:

3 Likes

@peerreynders The issue you created/linked appears to work for commas but I’m still having issues with spaces. Any idea if there’s a separate ticket for spaces? I wasn’t able to find anything.