【问题标题】:After Renaming Elixir/Phoenix Codebase: variable "X" does not exist and is being expanded to "X()"重命名 Elixir/Phoenix 代码库后:变量“X”不存在,正在扩展为“X()”
【发布时间】:2017-07-25 23:30:24
【问题描述】:

我将我的代码库从 Livestory 重命名为 Citybuilder。我对文件中的文本使用了查找和替换,然后使用 mv 重命名目录。 Livestory 的代码库搜索返回零结果。 https://stackoverflow.com/editing-help

当我运行mix phx.server 时,我得到:

variable "citybuilder" does not exist and is being expanded to "citybuilder()", please use parentheses to remove the ambiguity or change the variable name
  mix.exs:1

我尝试运行mix deps.cleanmix deps.get。同样的结果“城市建设者不存在”。

我在这里发现了一个类似的问题,但它不适用于我,因为我正在运行最新版本的 Elixir 和 Phoenix:

Phoenix setup failing: Compilation error, (KeyError) key :model not found

*

Mix.exs

defmodule citybuilder.Mixfile do
  use Mix.Project

  def project do
    [app: :citybuilder,
     version: "0.0.1",
     elixir: "~> 1.4",
     elixirc_paths: elixirc_paths(Mix.env),
     compilers: [:phoenix, :gettext] ++ Mix.compilers,
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     aliases: aliases(),
     deps: deps()]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [mod: {citybuilder.Application,  []},
      applications: [
        :logger, :postgrex, :ecto, :timex, :phoenix, :phoenix_html, :phoenix_pubsub,
        :phoenix_ecto, :cowboy, :gettext, :guardian, :comeonin, :recaptcha, :edeliver
      ]
    ]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_),     do: ["lib"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [{:phoenix, "~> 1.3.0-rc", override: true},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_ecto, "~> 3.2"},
     {:postgrex, ">= 0.0.0"},
     {:phoenix_html, "~> 2.6"},
     # from official repository, but not from hex, because latest patches are not released yet
     {:recaptcha, "~> 2.0", github: "samueljseay/recaptcha"},
     {:timex, "~> 3.0"},
     {:phoenix_live_reload, "~> 1.0", only: :dev},
     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"},
     {:guardian, "~> 0.14"},
     {:comeonin, "~> 3.0"},
     {:distillery, "~> 1.0"},
     {:edeliver, "~> 1.4.0"}]
  end

  # Aliases are shortcuts or tasks specific to the current project.
  # For example, to create, migrate and run the seeds file at once:
  #
  #     $ mix ecto.setup
  #
  # See the documentation for `Mix` for more info on aliases.
  defp aliases do
    ["ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
     "ecto.reset": ["ecto.drop", "ecto.setup"],
     "test": ["ecto.create --quiet", "ecto.migrate", "test"]]
  end
end

【问题讨论】:

  • 你能把mix.exs的完整内容贴出来吗?
  • 问题是你进行了不区分大小写的搜索和替换,Livestory 变成了citybuilder(而不是Citybuilder。)Elixir 不将citybuilder 识别为原子,而是尝试查找citybuilder 变量,最后调用citybuilder 函数。
  • 我知道案例在这次重命名中会成为一个问题。我在 IDE 中使用了查找和替换功能,但没有检查设置。我现在就改一下,谢谢。

标签: elixir phoenix-framework


【解决方案1】:

我进行了不区分大小写的搜索和替换,Livestory 变成了 citybuilder(而不是 Citybuilder)。Elixir 不将 citybuilder 识别为原子,而是尝试查找 citybuilder 变量并最终调用 citybuilder 函数。

我通过查找 citybuilder 并将其替换为 Citybuilder 来解决此问题。

注意:有些应用程序(如 postgres)要求 citybuilder 为小写。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 2013-12-17
    • 2017-04-23
    • 1970-01-01
    相关资源
    最近更新 更多