namespaceselixirphoenix-frameworkdotfileselixir-iex

How to Stop Forced Module Namespace in Elixir Phoenix iex Console?


When using the iex console from my Phoenix application, as follows:

iex -S mix phx.server

I cant seem to call System functions, such as System.stop(1) or System.halt(1) as it forces a namespace to the front of the module. An error results as that namespaced module doesnt exist.

** (UndefinedFunctionError) function MyApp.SomeNamespace.System.stop/1 is undefined or private

Why does it prepend a namespace to this core module? Why does it produce this error with a module like System, but not with modules like Enum, List, or Map ?

Also, if I use iex outside of my application source, I can call System.any_function as expected.

On further inspection, I can get it to work by calling Elixir.System.stop/1. Why do I need to prepend the System module with Elixir. but I dont need to do that for other Elixir modules?

Within my application code, I call things like System.backtrace or System.get_env with no aliasing or namespacing required. I also have no modules named System in the application (i.e., there is no Myapp.System or similar module defined).


Solution

  • Look for an iex.exs file. If there is such a file it is automatically run when iex is run. If you reference namespaces in iex.exs that would explain this behavior.

    You can find out more in the docs https://hexdocs.pm/iex/IEx.html#module-the-iex-exs-file