Many of us are using more advanced editors such as Vim, Visual Studio Code, etc,. We all depend on the linters too much to correct our mistakes such as syntax errors. So, what is this specific topic related to? If you have started asking this question and you have found this link means, you are in the right place.
Let’s consider our normal dev course:
- Below is a dummy test app of my making.
- I have done some changes and then try to recompile it! BOOM The
:noop
crops up!!!!!
What’s happening?
Most of the elixir developers know why it is showing and unfortunately, there isn’t a proper tool to solve it except manually exporting or aliasing the environment variable. Most of us are good with them! But for the new comers, I’m going to elaborate as to why this is happening!
- If you are using an elixir extension for linting, then you will be facing this situation
- The linter asynchronously compiles your code in default
MIX_ENV
mode which is dev mode - And reports the errors or does syntax check, then displays it to you through the editor interface
- You would have already started the server in
dev
mode and hence, when you try to compile the compiled code - IEx reports
:noop
Environment Variable as Solution:
-
Whenever you are starting your editor you would have to start it with a different environment other than
dev(MIX_ENV={other environment} {your editor invoking})
. -
Next thing is creating an alias with the editor invoking command along with
MIX ENVIRONMENT
.
How to solve if you are using VIM:
Add the following line to your ~/.vimrc
or vim config file:
au FileType elixir let $MIX_ENV = 'test'
This is an autocommand belonging to vimscript which checks for elixir filetype and exports an environment variable for linter to compile using test environment automatically if the opened filetype is elixir.
Now, if you make a change to your code and recompile on the shell, it will recompile without any problem! except human errors!
Why TEST environment specifically?
Because, the environment variable that you are exporting are by default are the compile time configs dev.exs, prod.exs and test.exs
, any other variable that you specify will result in compile time error, making you elixir based extensions fail!
For example, if you export MIX_ENV=dummy
, the your extensions will fail with an error, dummy.exs config file not found
!.