【发布时间】:2017-10-21 07:50:00
【问题描述】:
首先,我在 Windows 10 中进行开发。我在每次编译之前运行vcvarsall.bat amd64。我正在使用:
灵药 1.4.2
凤凰v1.2.1
我开始了一个全新的项目,制作了一个用户表,一切正常。我添加了comeonin来散列密码,我不能再创建用户了。我收到一个错误页面:function Comeonin.Bcrypt.hashpwsalt/1 is undefined (module Comeonin.Bcrypt is not available)
以下是相关文件中的代码:
Mix.exs
# mix.exs
...
def application do
[mod: {PollarAppV2, []},
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext,
:phoenix_ecto, :postgrex, :comeonin, :timex]]
end
...
defp deps do
[{:phoenix, "~> 1.2.1"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.6"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:comeonin, "~> 3.0"},
{:timex, "~> 3.0"}]
end
...
User.ex
# user.ex
...
defp generate_password_hash(changeset) do
case changeset do
%Ecto.Changeset{valid?: true, changes: %{password: password}} ->
put_change(changeset, :encrypted_password, Comeonin.Bcrypt.hashpwsalt(password))
_ ->
changeset
end
end
当我尝试保存调用 generate_password_hash 的用户时,我收到此错误:
控制台
[warn] The on_load function for module Elixir.Comeonin.Bcrypt returned { :error,
{:load_failed,
'Failed to load NIF library c:/code/phoenix/pollar_app_v2/_build/dev/lib/comeonin/priv/bcrypt_nif: \'Unspecified error\''}}
[info] Sent 500 in 16ms
[error] #PID<0.430.0> running PollarAppV2.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /users
** (exit) an exception was raised:
** (UndefinedFunctionError) function Comeonin.Bcrypt.hashpwsalt/1 is
undefined (module Comeonin.Bcrypt is not available)
(comeonin) Comeonin.Bcrypt.hashpwsalt("asdfasdf")
(pollar_app_v2) web/models/user.ex:40: PollarAppV2.User.generate_password_hash/1
(pollar_app_v2) web/controllers/user_controller.ex:17: PollarAppV2.UserController.create/2
(pollar_app_v2) web/controllers/user_controller.ex:1: PollarAppV2.UserController.action/2
(pollar_app_v2) web/controllers/user_controller.ex:1: PollarAppV2.UserController.phoenix_controller_pipeline/2
(pollar_app_v2) lib/pollar_app_v2/endpoint.ex:1: PollarAppV2.Endpoint.instrument/4
(pollar_app_v2) lib/phoenix/router.ex:261: PollarAppV2.Router.dispatch/2
(pollar_app_v2) web/router.ex:1: PollarAppV2.Router.do_call/2
(pollar_app_v2) lib/pollar_app_v2/endpoint.ex:1: PollarAppV2.Endpoint.phoenix_pipeline/1
(pollar_app_v2) lib/plug/debugger.ex:123: PollarAppV2.Endpoint."call
(overridable 3)"/2
(pollar_app_v2) lib/pollar_app_v2/endpoint.ex:1: PollarAppV2.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy)
c:/code/phoenix/pollar_app_v2/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
我已经多次运行mix deps.clean --all、mix deps.update --all、mix deps.compile、mix compile 等。它从不表示 nif 文件未编译,我可以在文件结构中的正确位置看到文件,但我无法在应用程序中访问 Bcrypt。关于如何解决这个问题的任何想法?
【问题讨论】:
-
您是否也尝试过
mix clean(或手动删除_build)? -
是的,这两个我都做过很多次了。我似乎找不到任何有效的方法。
-
哪个版本的 Comeonin?
-
另外你有没有安装mingw?
-
Comeonin 3.0.2 是的,我有 mingw。现在真正困扰我的是,如果我不断创建新项目,一遍又一遍地执行完全相同的过程,有时会奏效,有时却不会。例如,有些项目它永远不会起作用,而另一些项目它会起作用。真是令人沮丧。
标签: elixir phoenix-framework bcrypt