我在获取在我从事的项目之一中使用的依赖项版本时遇到问题。我想在我的代码中获取此依赖项的版本。有什么简单的方法可以做到这一点吗?
我尝试了以下方法:
{:ok, dependency_version} = Mix.Dep.cached
|> Enum.filter(fn(d) -> d.app == :dependency_name end)
|> hd
|> Map.fetch!(:status)
Run Code Online (Sandbox Code Playgroud)
但正如我在文档中读到的那样,如果设置了,Mix.dep.cached可能会返回一个空数组。MIX_NO_DEPS除了创建一个返回自身版本的依赖函数之外,还有其他可靠的方法可以做到这一点吗?
我的应用程序在尝试运行版本时遇到了这个致命问题:
** (MatchError) no match of right hand side value: {:error, {:inets, {'no such file or directory', 'inets.app'}}}
Run Code Online (Sandbox Code Playgroud)
在我的本地主机上运行它时它工作正常mix,但是 distillery 2 版本有这个问题。
我erlang-inets从 erlang 解决方案存储库安装了 ubuntu 软件包并做了另一个mix release,但这似乎没有解决它。
我缺少什么?
我mix fetch.btc在 phoenix 应用程序上有混合任务(lib/mix/tasks/fetch.btc.ex):
defmodule Mix.Tasks.Fetch.Btc do
use Mix.Task
def run(_args) do
res = HTTPoison.get!("https://blockchain.info/ticker")
IO.inspect(res)
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行时mix fetch.btc出现错误:
** (ArgumentError) argument error
(stdlib) :ets.lookup_element(:hackney_config, :mod_metrics, 2)
PROJ_DIR/deps/hackney/src/hackney_metrics.erl:27: :hackney_metrics.get_engine/0
PROJ_DIR/deps/hackney/src/hackney_connect.erl:78: :hackney_connect.create_connection/5
PROJ_DIR/deps/hackney/src/hackney_connect.erl:47: :hackney_connect.connect/5
PROJ_DIR/deps/hackney/src/hackney.erl:330: :hackney.request/5
lib/httpoison/base.ex:787: HTTPoison.Base.request/6
lib/httpoison.ex:128: HTTPoison.request!/5
lib/mix/tasks/fetch.btc.ex:14: Mix.Tasks.Fetch.Btc.run/1
(mix) lib/mix/task.ex:331: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2
(elixir) lib/code.ex:767: Code.require_file/2
Run Code Online (Sandbox Code Playgroud)
但在我的控制器中,这段代码res = HTTPoison.get!("https://blockchain.info/ticker")工作成功!
信息:
hackney: 1.15.1
httpoison: 1.5.0
phoenix: 1.4.3
Run Code Online (Sandbox Code Playgroud)
我正在关注Elixir lang的Miguel Camba教程.
在我尝试使用以下代码段之前一切正常:
get "/play/:story_name" do
conn = conn.resp_content_type("text/event-stream")
conn = conn.send_chunked(200)
iterator = File.iterator!("#{conn.params[:story_name]}.txt")
Enum.each iterator, fn(line) ->
{ :ok, conn } = conn.chunk "data: #{line}\n"
await conn, 1000, on_wake_up(&1, &2), on_time_out(&1)
end
conn
end
defp on_wake_up(arg1, arg2) do
# Nothing
end
defp on_time_out(arg1) do
# Nothing
end
我尝试过以下方法:
await conn, 1000, on_wake_up&(&1, &2), on_time_out&(&1)
await conn, 1000, on_wake_up(&(&1, &2)), on_time_out(&(&1))
await conn, 1000, on_wake_up(), on_time_out()
end
conn
end
defp on_wake_up() do
# Nothing … 我有一个mix.exs具有一些依赖项的文件:
def deps do
[{:nadia, "~> 0.4"}]
end
Run Code Online (Sandbox Code Playgroud)
假设我想将Nadia改为版本0.3.我很难做到这一点.
在进行更改后mix.exs,我无法获得Nadia的0.3版本.既不帮助我mix deps.update也不mix deps.unlock && mix deps.update帮助我.
我确信有办法做到这一点; 我找不到它.
提前致谢!
我正在使用 phoenix 创建服务器并使用编辑器 VSCode。
当我启动 server:mix phx.server并且我更改了代码时,它不会重新编译,我必须关闭并再次运行。
应该在可以自动重新编译的地方设置扩展或配置吗?
文件dev.exs
config :jwtuser, Jwtuser.Endpoint,
http: [port: 5000],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
cd: Path.expand("../assets", __DIR__)]]
Run Code Online (Sandbox Code Playgroud)
在mix.exs 中
def project do
[
app: :jwtuser,
version: "0.0.1",
elixir: "~> 1.4",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
start_permanent: Mix.env == :prod,
aliases: aliases(),
deps: deps(),
erlc_options: erlc_options()
]
end
Run Code Online (Sandbox Code Playgroud) mix test --color在我的项目中,我可以运行向终端添加一些彩色输出的命令。我想在全局范围内设置它,这样我就可以运行mix test它,它会自动识别我想要的输出颜色。
我尝试过的...
mix help,但看不到任何有关全局配置的信息。mix help test,但我似乎不清楚如何将选项添加到文件中mix.exs,或者是否可以在某处设置全局选项。我觉得这可能是可能的,但在没有提出任何建议后,我想我会在这里问。
== Compilation error in file lib/ecto/query.ex ==
** (Kernel.TypespecError) lib/ecto/query.ex:428: type dynamic/0 is a built-in type and it cannot be redefined
(elixir 1.15.0) lib/kernel/typespec.ex:961: Kernel.Typespec.compile_error/2
(stdlib 5.0.1) lists.erl:1599: :lists.foldl_1/3
(elixir 1.15.0) lib/kernel/typespec.ex:226: Kernel.Typespec.translate_typespecs_for_module/2
could not compile dependency :ecto, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile ecto --force", update it with "mix deps.update ecto" or clean it with "mix deps.clean ecto"
ERROR: Service 'cense_live_chat' failed to build: The command '/bin/sh -c …Run Code Online (Sandbox Code Playgroud) 当我尝试在hex上发布我的包的新版本时,它会输出以下警告:
WARNING! Excluded dependencies (not part of the Hex package):
ex_doc
Run Code Online (Sandbox Code Playgroud)
我运行命令的全文:
$ mix hex.publish
Publishing usefulness 0.0.5
Dependencies:
earmark >= 0.0.0
Files:
lib/usefulness.ex
lib/usefulness/stream.ex
lib/usefulness/string.ex
config/config.exs
test/test_helper.exs
test/usefulness_test.exs
mix.exs
README.md
LICENSE
App: usefulness
Name: usefulness
Description: Useful things
Version: 0.0.5
Build tools: mix
Licenses: Apache 2.0
Maintainers: afasdasd
Links:
Github: https://github.com/b-filip/usefulness
Elixir: ~> 1.2
WARNING! Excluded dependencies (not part of the Hex package):
ex_doc
Before publishing, please read Hex Code of Conduct: https://hex.pm/docs/codeofconduct
Proceed? [Yn]
Run Code Online (Sandbox Code Playgroud)
我不知道这个警告意味着什么
这是我project.deps在 …
我有一个phoenix应用程序,但是我需要在每次后端更改后手动重新启动服务器。 code_reload已启用并plug CodeReload正在使用。
我尝试生成一个新项目(mix phoenix.new --no-brunch),尝试了不同的编辑器(vim,vscode,atom和textedit),尝试始终plug CodeReload在端点中进行操作,并尝试手动将其设置MIX_ENV为dev-但是,更改文件时,项目仍无法编译。我应该如何追踪问题所在?
CodeReload不工作时运行mix phoenix.server或iex -S mix phoenix.server
Elixir 由 Erlang OTP 提供支持,它使用 Mix 作为构建工具来创建和运行应用程序。
我现在正在作为初学者学习长生不老药
我可以通过指定mix new sample从命令行创建 mix 应用程序, 并在其中编写一些代码来学习 elixir 和 mix 的基础知识。
可以使用命令mix run sample.exs运行exs和ex文件
我正在尝试编写代码来获取特定类型的数字,例如特定范围 (100000,20000) 之间的质数
我想将这两个数字 (100000,200000) 作为混合运行命令的参数,如mix run sample.exs 100000,200000并获得给定范围内的结果。
注意 - 我不想使用 escript 构建和可执行文件,只需要使用 mix run 命令而不是mix run -e
如何获取 args 作为 exs 文件中的输入值?
非常感谢
我正在尝试在我的另一台计算机上运行一个现有的 Elixir 项目,在一台新计算机上(两台都是 mac)。
当我运行 iex -S mix 时,我得到:
iex -S mix
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false]
11:47:52.651 [error] Loading of /Users/benjamin/vepo/api/_build/dev/lib/ranch/ebin/ranch_server.beam failed: :badfile
11:47:52.651 [error] beam/beam_load.c(1863): Error loading module ranch_server:
This BEAM file was compiled for a later version of the run-time system than 20.
To fix this, please recompile this module with an 20 compiler.
(Use of opcode 164; this emulator supports only up to 159.)
11:47:52.657 [info] Application ranch exited: :ranch_app.start(:normal, []) …Run Code Online (Sandbox Code Playgroud) 所以我正在学习 Elixir 和 Pheonix 看起来太多而无法开始学习,所以我使用 Plug and Poison 制作了一个简单的 JSON Rest API,但要查看任何更改,我需要停止服务器并mix run --no-halt再次运行。我来自nodeJS,它只nodemon跟踪依赖于根模块的所有文件,并在看到任何更改时重新加载整个服务器。有没有类似的 mix 或 Elixir 的东西?我知道您可以使用 OTP 重新加载代码的特定部分,如果我的服务器在保存时执行此操作,那就最好了,但现在我只想更快地响应我所做的事情。有人能指出我正确的方向吗?
elixir ×13
elixir-mix ×13
erlang ×3
beam ×1
dependencies ×1
distillery ×1
ecto ×1
hex ×1
httpoison ×1
httprequest ×1
plug ×1
version ×1