错误!与编译时相比,应用程序在运行时为键设置了不同的值

问题描述 投票:0回答:1

在我的 Elixir 项目中,我面临以下错误,并且不确定在哪里设置运行时值以匹配编译时值。

目前我唯一定义密钥 :app_url 的地方是在runtime.exs 中,PHX_HOST 被定义为环境变量。 :app_url 然后在 live.ex 中被引用,如

@app_url Application.compile_env(:myapp, :app_url)
根据错误信息,这是编译时值,并没有设置运行时值。

config :myapp,
  token_signing_secret: secret_key_base,
  app_url: System.get_env("PHX_HOST"),


ERROR! the application :myapp has a different value set for key :app_url during runtime compared to compile time. Since this application environment entry was marked as compile time, this difference can lead to different behaviour than expected:  

  * Compile time value was set to: "http://localhost:3030"
  * Runtime value was not set

To fix this error, you might:

  * Make the runtime value match the compile time one

  * Recompile your project. If the misconfigured application is a dependency, you may need to run "mix deps.compile myapp --force"

  * Alternatively, you can disable this check. If you are using releases, you can set :validate_compile_env to false in your release configuration. If you are using Mix to start your system, you can pass the --no-validate-compile-env flag


** (ErlangError) Erlang error: "aborting boot"
    (elixir 1.14.1) Config.Provider.boot/2
elixir phoenix-framework
1个回答
0
投票

如果您将以下行放入runtime.exs中,这将不起作用:

config :myapp,
    token_signing_secret: secret_key_base,
    app_url: System.get_env("PHX_HOST"),

您必须将其放入 config.exs 中。至少这对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.