DEV Community

aaronblondeau
aaronblondeau

Posted on

Running Elixir Phoenix on Windows

You've miraculously managed to install elixir, erlang, and friends on your Windows machine and you're ready to try out Phoenix. At some point in your tutorial you will be asked to run this command:

mix setup
Enter fullscreen mode Exit fullscreen mode

Good freaking luck - you're about to see this lovely error.

could not compile dependency :bcrypt_elixir, "mix compile" failed.
Enter fullscreen mode Exit fullscreen mode

And here is where Elixir's #1 fault comes to life yet again. So many things in the Elixir world are old, tired, and so far out of date it is a major pain in the ass to do anything. Along with the error above you'll get some instructions about fiddling around with some sort of visual studio paths and commands. You might even stumble across this post from the offending dependency : https://github.com/riverrun/comeonin/wiki/Requirements

I wonder when it was last updated? Yeah - over 3 years ago. That is actually relatively recent for Elixir! Still doesn't work though.

Here is what I did to get past the error:

1) Install Visual Studio 2022 Community Edition

These are the options that I checked to install - some of mine were from a previous setup. I believe that the "Desktop development with C++" is the key item. With Visual Studio you can always re-run the installer and add more items.

Image description

2) Once Visual Studio is installed, delete these folders from your Phoenix project :

  • _build
  • deps

3) Next launch the Windows Terminal / PowerShell app and immediately open up a new tab and choose "Developer Command Prompt for VS 2022" as the shell to run:

Image description

4) In the new shell, navigate to your Phoenix project and run "mix setup" again. If you're lucky, things will build and you'll be in business.

A couple of notes

  • Once I had completed the setup in the VS command shell I was able to use "mix phx.server" in my usual VS Code terminal window.
  • "mix test" however needed to be run for the first time back in the VS shell because for some too-clever-for-its-own-damn-good Elixir reason it re-builds all the dependencies that you just installed. I cannot currently get tests to pass due to the following:
** (UndefinedFunctionError) function Bcrypt.Base.gen_salt/2 is undefined (module Bcrypt.Base is not available)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)