elixir-ls icon indicating copy to clipboard operation
elixir-ls copied to clipboard

`Mix.install/2 can only be called with the same dependencies in the given VM` when debugging a plain `.exs` file

Open jarrodmoldrich opened this issue 7 months ago • 3 comments

Hi elixir-ls devs,

When debugging an .exs file without a mix.exs I ran into the following issue:

Started ElixirLS Debug Adapter v0.27.2
ElixirLS Debug Adapter built with elixir "1.18.3" on OTP "27"
Running on elixir "1.18.3 (compiled with Erlang/OTP 27)" on OTP "27"
Protocols are not consolidated

[...]

Running with MIX_ENV: dev MIX_TARGET: host
Running mix run --no-mix-exs test.exs
Mix task failed
Mix task exited with reason
an exception was raised:
    ** (Mix.Error) Mix.install/2 can only be called with the same dependencies in the given VM
        (mix 1.18.3) lib/mix.ex:618: Mix.raise/2
        test.exs:1: (file)
        (elixir 1.18.3) src/elixir_compiler.erl:77: :elixir_compiler.dispatch/4
        (elixir 1.18.3) src/elixir_compiler.erl:52: :elixir_compiler.compile/4
        (elixir 1.18.3) src/elixir_compiler.erl:39: :elixir_compiler.maybe_fast_compile/2
        (elixir 1.18.3) src/elixir_lexical.erl:13: :elixir_lexical.run/3
        (elixir 1.18.3) src/elixir_compiler.erl:17: :elixir_compiler.quoted/3
        (elixir 1.18.3) lib/module/parallel_checker.ex:120: Module.ParallelChecker.verify/1
returning code 1
Mix task exited with reason
an exception was raised:
    ** (Mix.Error) Mix.install/2 can only be called with the same dependencies in the given VM
        (mix 1.18.3) lib/mix.ex:618: Mix.raise/2
        test.exs:1: (file)
        (elixir 1.18.3) src/elixir_compiler.erl:77: :elixir_compiler.dispatch/4
        (elixir 1.18.3) src/elixir_compiler.erl:52: :elixir_compiler.compile/4
        (elixir 1.18.3) src/elixir_compiler.erl:39: :elixir_compiler.maybe_fast_compile/2
        (elixir 1.18.3) src/elixir_lexical.erl:13: :elixir_lexical.run/3
        (elixir 1.18.3) src/elixir_compiler.erl:17: :elixir_compiler.quoted/3
        (elixir 1.18.3) lib/module/parallel_checker.ex:120: Module.ParallelChecker.verify/1
returning code 1

12:14:40.298 [error] Process #PID<0.233.0> raised an exception
** (Mix.Error) Mix.install/2 can only be called with the same dependencies in the given VM
    (mix 1.18.3) lib/mix.ex:618: Mix.raise/2
    test.exs:1: (file)
    (elixir 1.18.3) src/elixir_compiler.erl:77: :elixir_compiler.dispatch/4
    (elixir 1.18.3) src/elixir_compiler.erl:52: :elixir_compiler.compile/4
    (elixir 1.18.3) src/elixir_compiler.erl:39: :elixir_compiler.maybe_fast_compile/2
    (elixir 1.18.3) src/elixir_lexical.erl:13: :elixir_lexical.run/3
    (elixir 1.18.3) src/elixir_compiler.erl:17: :elixir_compiler.quoted/3
    (elixir 1.18.3) lib/module/parallel_checker.ex:120: Module.ParallelChecker.verify/1
Received disconnect request

It runs fine in bash with mix run --no-mix-exs test.exs. Making a basic application and calling a function directly with -e seems to work fine. Is there a way to debug an a plain .exs?

Project: compile_crash.zip

.vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "mix_task",
      "name": "compile_crash",
      "request": "launch",
      "task": "run",
      "startApps": false,
      "taskArgs": ["--no-mix-exs", "test.exs"],
      "projectDir": "${workspaceRoot}",
      "exitAfterTaskReturns": false,
      "console": "internalConsole",
      "outputCapture": "std",
    }
  ]
}

test.exs:

Mix.install([{:req, "~> 0.5.10"}])

IO.puts "Hello world"

jarrodmoldrich avatar May 22 '25 02:05 jarrodmoldrich

Calling Mix.install in exs scripts is currently not supported. ElixirLS uses Mix.install in its launch script. Maybe there is a way to reset mix state

lukaszsamson avatar May 24 '25 07:05 lukaszsamson

Makes sense. Is it worth adding a line to the Known Issues/Limitations section? Happy to make a PR for it.

Related: https://github.com/elixir-lang/elixir/issues/12293

jarrodmoldrich avatar May 27 '25 01:05 jarrodmoldrich

I'm happy to close this now. Thanks again for your help 🙂

jarrodmoldrich avatar Jun 03 '25 00:06 jarrodmoldrich