A while back I made a PR to fix how .iex.exs worked so that it loaded the global/project versions correctly.
It was denied because it was not backwards compatible.
Still today, if you have an .iex.exs file that contains an import statement like the following, it crashes.
import Ecto.Query
Causes
$ iex ‹ruby-2.3.1›
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.2.5) - press Ctrl+C to exit (type h() ENTER for help)
Error while evaluating: /Users/mattwidmann/code/elixir/my_project/.iex.exs
** (CompileError) .iex.exs:3: module Ecto.Query is not loaded and could not be found
Does anyone else have this trouble? Would there be support for fixing these things in 1.3 or later?
I too would like a solution to this. It is often very convenient to have imports on my .iex.exs but doing so prevents a bare $ iex session which is rather inconvenient. I’ve tried a variety of ways to no avail I’m afraid.
@wojtekmach yes I’m aware. The problem isn’t with running iex -S mix, but rather the bare iex session as @benwilson512 mentioned. Sometimes I don’t want to start up the app and start the supervision tree. I just want to run something in the standard library.
@benwilson512 I have found a way to work, but I’d rather not have to have that hack in there. I can’t find the hack now but I think I had to either check function_exported?/2 or something like that. Not sure if that will work or not, I do remember it being one of the things I tried though as well as catching the exception by the failed import.
This still requires that the code compile. Yes I realize that there is a no compile flag. With every required flag the convenience decreases. At this point I just have aliases in my .iex.exs. A real solution that allows a regular iex call would be best.
Thats a great workaround, but I’d like to see an official solution to this problem.
When I get some time, I may submit a PR to allow compiling to fail when loading iex and just have it print out the exception. It’d be noisy but it would at least work that way.
In Elixir v1.3, you can do import_if_available and import_file_if_available. Both will be a no-op if the module or the file do not exist. Both should fix all problems mentioned in this thread.