Mazyod

Mazyod

ElixirLS Fails if Git Dependency Present (Visual Studio Code Extension)

Hello,

I have an issue with ElixirLS running in VSCode if a Git dependency is present. I tried to create a fresh project with a single git dependency, and immediately reproduced the problem. I am not sure how to debug this further, as the error message is very cryptic. Any help appreciated.

Below are the logs of a new elixir project, using latest Elixir version, and simply adding a single git dependency.


defmodule Alchemist.MixProject do
  use Mix.Project

  def project do
    [
      app: :alchemist,
      version: "0.1.0",
      elixir: "~> 1.17",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger]
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:jason, github: "michalmuskala/jason"}
    ]
  end
end

➜  alchemist git:(main) ✗ iex
Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]

Interactive Elixir (1.17.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> System.cmd("git", ["--git-dir=.git", "config", "remote.origin.url"], [cd: "/Users/mazyod/projects/new-elixir/alchemist/deps/jason"])
{"https://github.com/michalmuskala/jason.git\n", 0}

Running /Users/mazyod/.vscode/extensions/jakebecker.elixir-ls-0.22.1/elixir-ls-release/launch.sh
Preferred shell is zsh, relaunching
Looking for ASDF install
ASDF not found
Looking for mise executable
mise not found
Looking for rtx executable
rtx not found
Looking for vfox executable
vfox not found
Installing ElixirLS release v0.22.1
Running in /Users/mazyod/projects/new-elixir/alchemist
Install complete
[Info  - 9:02:37 AM] Started ElixirLS v0.22.1
[Info  - 9:02:37 AM] Running in /Users/mazyod/projects/new-elixir/alchemist
[Info  - 9:02:37 AM] ElixirLS built with elixir "1.17.2" on OTP "26"
[Info  - 9:02:37 AM] Running on elixir "1.17.2 (compiled with Erlang/OTP 26)" on OTP "26"
[Info  - 9:02:37 AM] Protocols are not consolidated
[Info  - 9:02:37 AM] Elixir sources not found (checking in /private/tmp/elixir-20240706-7373-erwccq/elixir-1.17.2). Code navigation to Elixir modules disabled.
[Info  - 9:02:37 AM] Received client configuration via workspace/configuration
%{"additionalWatchedExtensions" => [], "autoBuild" => true, "autoInsertRequiredAlias" => true, "dialyzerEnabled" => true, "dialyzerFormat" => "dialyxir_long", "dialyzerWarnOpts" => [], "enableTestLenses" => false, "envVariables" => %{"PATH" => "/opt/homebrew/bin"}, "fetchDeps" => false, "incrementalDialyzer" => true, "languageServerOverridePath" => "", "mixEnv" => "test", "mixTarget" => "", "projectDir" => "", "signatureAfterComplete" => true, "suggestSpecs" => true, "trace" => %{"server" => "off"}}
[Info  - 9:02:37 AM] Registering for workspace/didChangeConfiguration notifications
[Info  - 9:02:37 AM] Starting build with MIX_ENV: test MIX_TARGET: host
[Info  - 9:02:37 AM] client/registerCapability succeeded
[Info  - 9:02:37 AM] Registering for workspace/didChangeWatchedFiles notifications
[Info  - 9:02:37 AM] client/registerCapability succeeded
[Info  - 9:02:37 AM] Loaded DETS databases in 17ms
[Error - 9:02:37 AM] Process #PID<0.255.0> raised an exception
** (ErlangError) Erlang error: :enoent
    (elixir 1.17.2) lib/system.ex:1114: System.cmd("git", ["--git-dir=.git", "config", "remote.origin.url"], [cd: "/Users/mazyod/projects/new-elixir/alchemist/deps/jason"])
    (mix 1.17.2) lib/mix/scm/git.ex:312: Mix.SCM.Git.get_rev_info/0
    (mix 1.17.2) lib/mix/scm/git.ex:75: anonymous fn/2 in Mix.SCM.Git.lock_status/1
    (elixir 1.17.2) lib/file.ex:1665: File.cd!/2
    (mix 1.17.2) lib/mix/dep.ex:425: Mix.Dep.check_lock/1
    (elixir 1.17.2) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (mix 1.17.2) lib/mix/tasks/deps.loadpaths.ex:76: Mix.Tasks.Deps.Loadpaths.deps_check/2
    (mix 1.17.2) lib/mix/tasks/deps.loadpaths.ex:48: Mix.Tasks.Deps.Loadpaths.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/tasks/loadpaths.ex:37: Mix.Tasks.Loadpaths.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/tasks/compile.ex:153: Mix.Tasks.Compile.run/1
    (mix 1.17.2) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
    (language_server 0.22.1) lib/language_server/build.ex:442: ElixirLS.LanguageServer.Build.run_mix_compile/1
    (language_server 0.22.1) lib/language_server/build.ex:80: anonymous fn/3 in ElixirLS.LanguageServer.Build.build/3
    (stdlib 5.2.3) timer.erl:270: :timer.tc/2
Received $/cancelRequest for unknown request id: 8
Received $/cancelRequest for unknown request id: 11

Marked As Solved

undeadlol1

undeadlol1

I have the same problem. No amount of googling helped me to solve it.

The only workaround I could find is to set "elixirLS.autoBuild": false, in the VS Code user settings.

Also Liked

NobbZ

NobbZ

This is exactly why I proposed to try from terminal.

It is a known issue that applications started from the GUI will not see the same PATH (and other environment variables) as those started from a terminal/shell.

I haven’t used VScode in a while, and even less did I use the debugging facilities… Years ago, I debugged a similar issue with a coworker (on Linux though and not elixir LS related), and we eventually checked the PATH environment variable and have seen significant discrepancies between the one defined in the shell and the one as seen by VScode from launcher.

There we mitigated by using /etc/environment.d to “correct” the PATH.

Though sadly I do not remember anymore how we checked the PATH as seen by VScode back then… Also MacOS does not have an equivalent of /etc/environment.d AFAIR.

jdiago

jdiago

What happens if you delete the .elixir_ls directory and restarted vs code? That’s what I tend to do when elixir ls freaks out about deps.

dimitarvp

dimitarvp

I was about to suggest the same as @jdiago, but not only delete the .elixir_ls directory:

rm -rf .elixir_ls deps _build
mix do deps.get, compile

After that completes, start your IDE and wait for ElixirLS to rebuild its cache.

undeadlol1

undeadlol1

I solved the problem on my side by addressing several issues. I’m not sure which single step fixed it for me, but I had to deal with two main problems:

  1. VS Code ElixirLS configuration (especially the PATH property)

  2. A broken ASDF Elixir installation (likely related to SSL issues)

The problem was most likely with my PATH configuration. If your project doesn’t use ASDF, you might be able to skip the ASDF steps.

Since I’m new to Elixir I don’t know what specific steps helped me thus I will list all of them:

  1. Uninstall the ElixirLS extension from VS Code.

  2. Remove build artifacts:

  3. Run this command in your project directory:

rm -rf deps _build .elixir_ls
  1. Uninstall ASDF plugins:

It seems that uninstalling ASDF itself does not remove the Elixir plugin. Make sure that running asdf list shows no versions installed.

  1. Uninstall ASDF.

  2. Reinstall ASDF (I used brew install asdf on macOS).

  3. Install the ASDF plugins for Elixir and Erlang:

asdf plugin add elixir https://github.com/asdf-vm/asdf-elixir.git
asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git
  1. Run asdf install to install the versions of Erlang and Elixir.

  2. Fix SSL problems:

Install the necessary SSL dependencies:

brew install coreutils automake autoconf openssl@3.0 libyaml readline libxslt libtool unixodbc wxwidgets fop

Then, set the proper SSL options:

export KERL_CONFIGURE_OPTIONS="--disable-debug --without-javac --with-ssl=$(brew --prefix openssl@3.0)"
  1. Comment out all custom ElixirLS configurations in VS Code (you can leave the formatter configuration intact). In my case, the PATH option was likely causing the problems.

  2. Install the ElixirLS extension in VS Code again.

  3. Restart VS Code (or use the “Restart Extension Host” command from the command palette).

  4. Wait a little while for Elixir compilation to complete (there is no visible indication that compilation is running).

Everything should be working now.

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement