运行phoenix服务器时如何忽略编译警告

Ben*_*ser 1 elixir phoenix-framework

我正在尝试从命令行运行phoenix服务器,iex -S mix phx.server但在编译过程中不断收到有关未使用变量的警告。

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

我不在乎这些警告,因为我正处于开发过程中,这些var最终将被使用或抛弃。我尝试了传递-h和其他明智的选择,但是它们都不起作用,而且我在文档中找不到有关如何phx.server传递或覆盖选项到编译器的任何信息。

我看过这些文档,但它们并没有帮助

我尝试传递该--no-compile选项,但这是不行的,因为它使我无法在开发期间重新编译。我目前正在使用IO.inspectvars,这似乎足以让我通过未使用的vars检查,但是我宁愿能够在编译器中禁用此标志,而不是乱扔我的代码IO.inspect

She*_*yar 5

错误消息很清楚:

由于使用该--warnings-as-errors选项时出现警告,编译失败

您在编译器上启用了此特定标志,它在警告时返回非零的退出代码。由于您没有在命令行中手动传递选项,因此可能是:

  • 通过ENV变量设置(可能由Elixir版本管理器设置)
  • mix别名或任务中传递
  • 但是,很可能它是在您的Mixfile under中硬编码的elixirc_options。您可以这样禁用它:

    # mix.exs
    elixirc_options: [warnings_as_errors: false]
    
    Run Code Online (Sandbox Code Playgroud)

附带说明,要获得有关编译器选项的帮助,应使用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
Run Code Online (Sandbox Code Playgroud)

另请参见:如果出现编译时警告,则使编译器退出