Can't start Phoenix Server

Can’t start Phoenix server or run ANY mix tasks.

$ mix phx.server
** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1    
    
    The following arguments were given to IO.chardata_to_string/1:
    
        # 1
        DIR
    
    Attempted function clauses (showing 2 out of 2):
    
        def chardata_to_string(string) when is_binary(string)
        def chardata_to_string(list) when is_list(list)
    
    (elixir) lib/io.ex:461: IO.chardata_to_string/1
    (elixir) lib/path.ex:677: Path.expand_home/1
    (elixir) lib/path.ex:183: Path.expand/2
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:888: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:240: :erl_eval.expr/5
    (stdlib) erl_eval.erl:232: :erl_eval.expr/5
    (stdlib) erl_eval.erl:233: :erl_eval.expr/5

I think it’s because I updated from Phoenix v1.4.3 to v1.4.4 and this app is using v1.4.3. That’s the only thing I can think of because it was running just fine before that and I didn’t change anything. I tried to change the Phoenix version in my app to 1.4.4 and then run either mix deps.get OR mix deps.update to update the mix.lock; but again, none of the mix tasks will run, same error :).

My other Phoenix app on 1.4.4 runs just fine by the way. If anyone has any ideas please let me know.

Have you tried deleting your _build directory?

2 Likes

More context please. Is this a brand new app? Which Erlang age Elixir versions are you using? Which version of Phoenix?

1 Like

Does this only happen when you start the server or when you compile using mix compile as well?

If the latter, have you tried deleting deps and _build folders and then refetching dependencies and recompiling them?

1 Like

@sneako Just tried, didn’t work.

@NobbZ Tried this as well and no luck.

@dimitarvp brand new app with 1 model setup and 1 LiveView, simple todo app from a tutorial. Was working fine and then I created another new app to work on an upgraded Phoenix from 1.4.3 to 1.4.4. Now I am going back without having changed anything else.

Erlang/OTP 21 [erts-10.3.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]

Elixir 1.8.1 (compiled with Erlang/OTP 21)
defp deps do
    [
      {:phoenix, "~> 1.4.4"},
      {:phoenix_pubsub, "~> 1.1"},
      {:phoenix_ecto, "~> 4.0"},
      {:ecto_sql, "~> 3.0"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 2.11"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"},
      {:phoenix_slime, github: "slime-lang/phoenix_slime"},
      {:phoenix_inline_svg, "~> 1.1"},
      {:distillery, "~> 2.0", runtime: false},
      {:phoenix_live_view, github: "phoenixframework/phoenix_live_view"}
    ]
  end

The error seems really strange. Can you show Erlang and Elixir versions and say how did you install them?

Yes, I showed it in the last post. Erlang/OTP 21 and Elixir 1.8.1. Installed with Homebrew.

Sorry, my bad.

I’d theorise you need to install both through asdf. Your version of Elixir might not be compiled against Erlang/OTP 21.x.

No worries :). Well my other apps work, and if I create a new Phoenix app it also works fine. It’s just this one directory/app that’s having problems and I’d really like to understand why.

So it fails on a plain compile as well?

Installing dependencies though works?

1 Like

Nothing works. The dependencies were already installed before when it was working. But now it’s not working (assuming because I installed Phoenix 1.4.4).

So you probably have some error in one of the files evaluated by mix very early in the stage of compilation.

What is the output of grep -i -n DIR mix.exs config/*.exs?

edit confused argument order for grep…

2 Likes
$ grep -i -n DIR mix.exs config/*.exs
config/dev.exs:27:      cd: Path.expand("../assets", DIR)
config/prod.exs:47:# no data is ever sent via http, always redirecting to https:

Feels like we’re on the right path, because the main error we’re talking about is evaluating the DIR variable. I must admit, I’m a little out of my depth and haven’t been able to find anything in Google relating to this error, aside from some issue with Mailgun (which I’m not using in this app).

$ mix phx.server
** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1    
    
    The following arguments were given to IO.chardata_to_string/1:
    
        # 1
        DIR
    
    Attempted function clauses (showing 2 out of 2):
    
        def chardata_to_string(string) when is_binary(string)
        def chardata_to_string(list) when is_list(list)
    
    (elixir) lib/io.ex:461: IO.chardata_to_string/1
    (elixir) lib/path.ex:677: Path.expand_home/1
    (elixir) lib/path.ex:183: Path.expand/2
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:888: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:240: :erl_eval.expr/5
    (stdlib) erl_eval.erl:232: :erl_eval.expr/5
    (stdlib) erl_eval.erl:233: :erl_eval.expr/5

UPDATE: FOUND IT!

Somehow in my dev.exs file, DIR was renamed to DIR (cd: Path.expand("../assets", DIR)).

I have no idea how this happened. UPDATE: checked my commit history and no record of this change either… hmmm the grand mystery may never be solved.

Renaming DIR to __DIR__ fixed it.

config :myapp, MyappWeb.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: [
    nodemon: [
      "--watch",
      "webpack.config.js",
      "--watch",
      "postcss.config.js",
      "--watch",
      "package.json",
      "--exec",
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch-stdin",
      cd: Path.expand("../assets", __DIR__)
    ]
  ]

Thanks a ton everyone :). Hope this will save someone else some time in the future.

5 Likes

Thanks! When i was trying to build my docker images I encountered this problem and just could not get out, you saved me life!

2 Likes