mgwidmann

mgwidmann

A while back I made a PR to fix how .iex.exs worked so that it loaded the global/project versions correctly.
https://github.com/elixir-lang/elixir/pull/3824

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?

Showing Posts 1 to 10

wojtekmach

wojtekmach

Hex Core Team

I think you’d need to run iex -S mix to use non-stdlib code in your .iex.exs. See: ** (CompileError) iex: undefined function from/2, inadequate error message · Issue #1665 · phoenixframework/phoenix · GitHub

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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.

mgwidmann

mgwidmann OP

@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.

ubernil

ubernil

You can always use “iex -S mix run --no-start” to have all your project code and dependencies loaded, but no applications started.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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.

mgwidmann

mgwidmann OP

I think the real problem is as @benwilson512 stated, allowing a bare iex session even if the .iex.exs can’t be compiled.

Additionally it’d be nice to do something like my rejected PR did, which allows proper handling of the global .iex.exs when present.

mgwidmann

mgwidmann OP

Do you think iex should just print a warning or compiler error when you start it up and continue loading?

minhajuddin

minhajuddin

May not be the perfect solution but you could override the .iex.ex file like below

alias bare-iex='iex --dot-iex <(echo "")'

Using this alias bare-iex should work without loading the .iex.exs file

mgwidmann

mgwidmann OP

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.

josevalim

josevalim

Creator of Elixir

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.

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews