Windows 上的 Addict hex 包依赖性错误不会发生在 Mac 上

Addict hex package dependencies error on Windows that does not occur on Mac

我尝试在我的 Phoenix Project 中安装 addict 包,但出现错误。 我在一位同事的 Mac 上尝试了完全相同的过程,他没有得到错误,而我在 Windows 上做了。 该错误来自 comeonin 依赖项。我也在 Phoenix 0.14 和昨天发布的 0.15 更新中都试过了。

重建步骤:

  1. 创建一个新项目并运行它

    $ mix phoenix.new testAddict
    $ cd testAddict
    $ mix ecto.create
    $ mix phoenix.server
    
  2. 在mix.exs中添加瘾君子:

    defp deps do
      [{:phoenix, "~> 0.15"},
        {:phoenix_ecto, "~> 0.8"},
        {:postgrex, ">= 0.0.0"},
        {:phoenix_html, "~> 1.4"},
        {:phoenix_live_reload, "~> 0.5", only: :dev},
        {:addict, "~> 0.0.5"},
        {:cowboy, "~> 1.0"}]
    end
    
  3. 编译依赖:

    $ mix deps.get

结果:

Running dependency resolution
Dependency resolution completed successfully
  addict: v0.0.5
  comeonin: v0.11.3
  mailgun: v0.0.2
* Getting addict (Hex package)
Checking package (https://s3.amazonaws.com/s3.hex.pm/tarballs/addict-0.0.5.tar)
Using locally cached package
Unpacked package tarball (c:/Users/mesos_000/.hex/packages/addict-0.0.5.tar)
* Getting mailgun (Hex package)
Checking package (https://s3.amazonaws.com/s3.hex.pm/tarballs/mailgun-0.0.2.tar)
Using locally cached package
Unpacked package tarball (c:/Users/mesos_000/.hex/packages/mailgun-0.0.2.tar)
* Getting comeonin (Hex package)
Checking package (https://s3.amazonaws.com/s3.hex.pm/tarballs/comeonin-0.11.3.tar)
Using locally cached package
Unpacked package tarball (c:/Users/mesos_000/.hex/packages/comeonin-0.11.3.tar)
  1. 运行 又是凤凰项目:

    $ mix phoenix.server

结果(这里是错误):

==> mailgun
Compiled lib/mailgun.ex
Compiled lib/client.ex
Generated mailgun app
==> comeonin
could not compile dependency comeonin, mix compile failed. You can recompile this dependency with `mix deps.compile comeonin` or update it with `mix deps.update comeonin`

** (ErlangError) erlang error: :enoent
    (elixir) lib/system.ex:440: System.cmd("nmake", ["/F", "Makefile.win", "priv\bcrypt_nif.dll"], [stderr_to_stdout: true])
    mix.exs:15: Mix.Tasks.Compile.Comeonin.run/1
    (elixir) lib/enum.ex:977: anonymous fn/3 in Enum.map/2
    (elixir) lib/enum.ex:1261: Enum."-reduce/3-lists^foldl/2-0-"/3
    (elixir) lib/enum.ex:977: Enum.map/2
    (mix) lib/mix/tasks/compile.all.ex:15: Mix.Tasks.Compile.All.run/1
    (mix) lib/mix/tasks/compile.ex:64: Mix.Tasks.Compile.run/1
    (mix) lib/mix/tasks/deps.compile.ex:105: anonymous fn/2 in Mix.Tasks.Deps.Compile.do_mix/1
  1. 尝试建议:

    $ mix deps.compile comeonin

结果:

Running dependency resolution
Dependency resolution completed successfully
  comeonin: v0.11.3
$ mix phoenix.server

结果:同上错误。

$ mix deps.update comeonin

结果:

==> comeonin
could not compile dependency comeonin, mix compile failed. You can recompile this dependency with `mix deps.compile comeonin` or update it with `mix deps.update comeonin`

** (ErlangError) erlang error: :enoent
    (elixir) lib/system.ex:440: System.cmd("nmake", ["/F", "Makefile.win", "priv\bcrypt_nif.dll"], [stderr_to_stdout: true])
    mix.exs:15: Mix.Tasks.Compile.Comeonin.run/1
    (elixir) lib/enum.ex:977: anonymous fn/3 in Enum.map/2
    (elixir) lib/enum.ex:1261: Enum."-reduce/3-lists^foldl/2-0-"/3
    (elixir) lib/enum.ex:977: Enum.map/2
    (mix) lib/mix/tasks/compile.all.ex:15: Mix.Tasks.Compile.All.run/1
    (mix) lib/mix/tasks/compile.ex:64: Mix.Tasks.Compile.run/1
    (mix) lib/mix/tasks/deps.compile.ex:105: anonymous fn/2 in Mix.Tasks.Deps.Compile.do_mix/1

编辑: 在 José Valim 的建议下,我安装了 Visual Studio Express 来获取 nmake。我还必须从 erlang 站点安装更新版本的 erlang+otp。 最后,我现在遇到了一个不同但仍然相关的错误:

C:\Users\mesos_000\Desktop\elixir Projects\testeAddict>mix deps.compile comeonin
==> comeonin

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

'priv\bcrypt_nif.dll' is up-to-date

Compiled lib/comeonin/config.ex
Compiled lib/comeonin/pbkdf2_base64.ex
Compiled lib/comeonin/bcrypt_base64.ex
Compiled lib/comeonin/tools.ex
Compiled lib/comeonin.ex
Compiled lib/comeonin/password.ex
Compiled lib/comeonin/pbkdf2.ex

== Compilation error on file lib/comeonin/bcrypt.ex ==
** (MatchError) no match of right hand side value: {:error, :on_load_failure}
    (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6

could not compile dependency comeonin, mix compile failed. You can recompile this dependency with `mix deps.compile comeonin` or update it with `mix deps.update comeonin`

此外,在我的 Ubuntu VM 上安装 erlang 完全解决了那里的问题。问题只存在于我的 Windows 8.1.

您需要安装nmake。引用另一个 SO 答案:

NMake is part of Microsoft's build tools for building C++ projects. You can get nmake as well as the MSVC++ compiler by downloading Visual C++ Express. Visual C++ Express runs perfectly fine on Windows 7.

来源:https://superuser.com/questions/146577/where-do-i-find-nmake-for-windows-7

解决 comeonin 依赖错误的说明已更新,我按照他们所说的设法解决了这个问题:

打开 Visual Studio 的开发人员命令提示符(在 Windows 8、8.1 和 10 中,它位于 Visual Studio 应用程序菜单下)。

$ cd "\Program Files (x86)\Microsoft Visual Studio 12.0\VC"
$ vcvarsall amd64

comeonin 依赖项现在应该可以编译。