4

I'm trying to run phoenix server from the command line with iex -S mix phx.server but I keep getting warnings on compilation about unused variables.

Compilation failed due to warnings while using the --warnings-as-errors option

I don't care about these warnings as i am in the middle of development and these vars will eventually be used or tossed out. I have tried passing -h and other sensible options, but none of them work and I can't find anything in the docs about how to get phx.server to pass or override options to the compiler.

I've seen these docs and they haven't helped

I have tried passing the --no-compile option but this is a no-go since it leaves me unable to recompile during development. I am currently using IO.inspect to call the vars and this seems to be "good enough" for me to pass the unused vars check, but I would rather be able to disable this flag in the compiler rather than littering my code with IO.inspect

Ben Glasser
  • 3,216
  • 3
  • 24
  • 41

2 Answers2

9

The error message is pretty clear on that:

Compilation failed due to warnings while using the --warnings-as-errors option

You have this specific flag enabled on the compiler, it returns a non-zero exit code on warnings. Since you're not passing the option manually in the command-line, it's possible that it's being:

  • Set via an ENV variable (possibly by an Elixir version manager)
  • Being passed in a mix alias or task
  • But most probably it's hardcoded in your Mixfile under elixirc_options. You can disable it like this:

    # mix.exs
    elixirc_options: [warnings_as_errors: false]
    

On a side note, to get help on compiler options, you should use elixirc:

± % elixirc --help
Usage: elixirc [elixir switches] [compiler switches] [.ex files]

  -o                        The directory to output compiled files

  --help, -h                Prints this message and exits
  --ignore-module-conflict  Does not emit warnings if a module was previously defined
  --no-debug-info           Does not attach debug info to compiled modules
  --no-docs                 Does not attach documentation to compiled modules
  --verbose                 Prints compilation status
  --version, -v             Prints Elixir version and exits
  --warnings-as-errors      Treats warnings as errors and return non-zero exit code

** Options given after -- are passed down to the executed code
** Options can be passed to the Erlang runtime using ELIXIR_ERL_OPTIONS
** Options can be passed to the Erlang compiler using ERL_COMPILER_OPTIONS

Also see: Get the compiler to exit if a compile-time warning is raised

Sheharyar
  • 73,588
  • 21
  • 168
  • 215
  • adding `elixirc_options: [warnings_as_errors: false]` to `project/0` in `mix.exs` has no effect. – Ben Glasser Nov 19 '18 at 19:37
  • I understand why it's happening. I need to know how to turn it off. – Ben Glasser Nov 19 '18 at 19:38
  • Then there's probably an env variable or mix alias that's passing it as a flag. Take a look at the env flags exported by your elixir version manager and all tasks/aliases defined by your application. – Sheharyar Nov 19 '18 at 19:42
2

If you run mix compile --warnings-as-errors=false first, then you can run iex -S mix phx.server without issues as it will already be compiled and should just start up.

Andrea Salicetti
  • 2,423
  • 24
  • 37