Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mix igniter.gen.task my_lib.install fails with UndefinedFunctionError when igniter accidentally installed as dependency #191

Open
lawik opened this issue Jan 15, 2025 · 8 comments
Labels
bug Something isn't working

Comments

@lawik
Copy link

lawik commented Jan 15, 2025

Describe the bug
Building a library and wanting to use Igniter to inject some config I wanted to make a task and saw the provided generator. It fails with an error.

To Reproduce

Using Igniter 0.5.8 and having run a mix deps.compile:

mix igniter.gen.task ex_verity.installer
** (UndefinedFunctionError) function Rewrite.new/0 is undefined (module Rewrite is not available)
    Rewrite.new()
    lib/igniter.ex:95: Igniter.new/0
    lib/mix/tasks/igniter.gen.task.ex:2: Mix.Tasks.Igniter.Gen.Task.run/1
    (mix 1.17.2) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.17.2) lib/mix/cli.ex:96: Mix.CLI.run_task/2
    /home/lawik/.asdf/installs/elixir/1.17.2-otp-27/bin/mix:2: (file)

Expected behavior
I thought it would work <3

** Runtime

  • Elixir version: 1.17.2

  • Erlang version: 27.0.1

  • OS: Linux/Ubuntu

  • Igniter version: 0.5.8

@lawik lawik added the bug Something isn't working label Jan 15, 2025
@zachdaniel
Copy link
Contributor

Very strange, I used this just yesterday! That kind of failure typically comes from some kind of problem with compilation or dependencies etc.

not sure why it would happen. Can you try things like removing your _build directory? Or force compiling deps?

@lawik
Copy link
Author

lawik commented Jan 15, 2025

lawik@monolith:~/flurgh$ mix igniter.new flurgh --with nerves.new
# ..
lawik@monolith:~/flurgh$ mix igniter.gen.task flurgh.install
** (UndefinedFunctionError) function Rewrite.new/0 is undefined (module Rewrite is not available)
    Rewrite.new()
    lib/igniter.ex:95: Igniter.new/0
    lib/mix/tasks/igniter.gen.task.ex:2: Mix.Tasks.Igniter.Gen.Task.run/1
    (mix 1.17.2) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.17.2) lib/mix/cli.ex:96: Mix.CLI.run_task/2
    /home/lawik/.asdf/installs/elixir/1.17.2-otp-27/bin/mix:2: (file)
lawik@monolith:~/flurgh$ mix compile
Compiling 1 file (.ex)
Generated flurgh app
lawik@monolith:~/flurgh$ mix igniter.gen.task flurgh.install
** (UndefinedFunctionError) function Rewrite.new/0 is undefined (module Rewrite is not available)
    Rewrite.new()
    lib/igniter.ex:95: Igniter.new/0
    lib/mix/tasks/igniter.gen.task.ex:2: Mix.Tasks.Igniter.Gen.Task.run/1
    (mix 1.17.2) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.17.2) lib/mix/cli.ex:96: Mix.CLI.run_task/2
    /home/lawik/.asdf/installs/elixir/1.17.2-otp-27/bin/mix:2: (file)

Force compiling deps, clearing _build, nothing. I wonder if I have a bad archive installed..

lawik@monolith:~$ mix new floop
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/floop.ex
* creating test
* creating test/test_helper.exs
* creating test/floop_test.exs

Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:

    cd floop
    mix test

Run "mix help" for more commands.
lawik@monolith:~$ cd floop/
lawik@monolith:~/floop$ mix igniter.install jason
Compiling 1 file (.ex)
Generated floop app
** (UndefinedFunctionError) function Igniter.Util.Install.install/2 is undefined (module Igniter.Util.Install is not available)
    Igniter.Util.Install.install("jason", [])
    (mix 1.17.2) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.17.2) lib/mix/cli.ex:96: Mix.CLI.run_task/2
    /home/lawik/.asdf/installs/elixir/1.17.2-otp-27/bin/mix:2: (file)

@lawik
Copy link
Author

lawik commented Jan 15, 2025

Even with updated archive and just a plain mix igniter.new floof, it will not. mix igniter.install jason works but the mix igniter.gen.task does not.

@zachdaniel
Copy link
Contributor

Very weird. What does mix archive show?

@zachdaniel
Copy link
Contributor

I even tried using elixir 1.17.2 and I still can't reproduce 🤔 🤔 🤔

@lawik
Copy link
Author

lawik commented Jan 15, 2025

lawik@monolith:~$ mix archive
* hex-2.1.1
* igniter-0.3.34
* igniter_new-0.5.6
* nerves_bootstrap-1.13.1
* phx_new-1.7.14
Archives installed at: /home/lawik/.asdf/installs/elixir/1.17.2-otp-27/.mix/archives

Maybe I done did a crime with igniter-0.3.34 at one point?

@lawik
Copy link
Author

lawik commented Jan 15, 2025

mix archive.uninstall igniter

@lawik lawik closed this as completed Jan 15, 2025
@zachdaniel
Copy link
Contributor

Oh, wow yeah that would do it. Since archives are installed without dependencies, that would cause the mix tasks from igniter to be installed globally and then not find dependencies when run. I'm actually going to reopen this, because I think that mix archive.install hex igniter is the sort of thing that people are going to do again in the future. We should have a check for it at the beginning of igniter tasks :)

@zachdaniel zachdaniel reopened this Jan 15, 2025
@zachdaniel zachdaniel changed the title mix igniter.gen.task my_lib.install fails with UndefinedFunctionError mix igniter.gen.task my_lib.install fails with UndefinedFunctionError when igniter accidentally installed as dependency Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants