RuntimeError - instructed to restart server for changing a file that I have not changed

I have been getting this for a while now when changing a controller in web/controllers/user_controller.ex

** (RuntimeError) could not compile application: myapp.

You must restart your server after changing the following config or lib files:

  * _build/dev/lib/myapp/.compile.lock

I didn’t change a lib or config file, so why do I have to restart?

I’m using Atom with the atom-elixir plugin, so I’m not sure if by hitting cmd+S if it writes to disk on all files (including some lib files maybe?)… Anyone else experiencing this?

1 Like

I also see that almost every time (on many different projects) hitting save on a single file results in recompiling all dependencies, which seems crazy to me. Don’t know whats going on…

2 Likes

Can you try to reproduce that in an application so we can try to track down the issue? We should not track anything in _build, so it feels like it is either a configuration issue or something unexpected. What is your Phoenix version? Are you using umbrella apps?

3 Likes

Yeah I suspect it is something with my setup I just don’t know where to look for the issue. I will try it with a new Phoenix project tonight (using 1.2 with elixir 1.4).

It has been happening to me for some time so it’s hard to say what I’ve introduced to cause it.

2 Likes

Sorry I’m a little later than I expected. The compile lock error is more difficult to reproduce, as it seems to happen when I’m actually working the most, rather than if I try to replicate it…

So I was not able to reproduce anything with a brand new Phoenix project. But I do have an open source project that is recompiling all dependencies when any web or lib files changes. Here it is:

Every time the server is started up with mix phoenix.server (after having hit save on any file in the project, say the user controller mentioned below), it recompiles all dependencies.

I’ll keep trying to get a more reproducible set of steps for the compile lock issue.

2 Likes

I could not reproduce this. :frowning: Touching user_controller and then running mix phoenix.server recompiled only the user controller and not the whole app. I am using Elixir v1.4.1.

This is what I got from mix xref graph:

If A points to B, it means that A may be recompiled if B changes. If the edge has a (compile) note, then the recompilation is guaranteed. As you can see, nothing points to UserController, so changing it doesn’t recompile anything else.

3 Likes

Yeah I suspect like I said that it’s something in my setup that’s doing it. I’ll try again using a different editor and see if that makes an impact.

2 Likes

Under another project which is private I’m able to reproduce it by commenting and uncommenting an IO.inspect line in a file in the lib folder. I tried disabling this atom package https://github.com/msaraiva/atom-elixir and wasn’t able to reproduce it in the few minutes I was trying. After turning it back on I was able to reproduce the lock issue in under a minute or two. I’ll try leaving that package disabled longer to see if the issue is cleared up.

@msaraiva curious if you have any input…

4 Likes

So it is not the atom-elixir package :icon_sad: (sorry!)… I’m trying to disable one plugin at a time to see if I can find which one it is…

Is there no one else who has this problem?

1 Like

I am also having the same problem. My app creates and saves files. After a file is created and if I reload a page on my site, I get the error “You must restart your server after changing the following config or lib files”.

Update:
I finally figured out the problem. It was because I was calling File.cd!(my_new_path) to change directory. I have created an issue https://github.com/phoenixframework/phoenix/issues/2337

I’m running into a similar issue here and I don’t know where to start debugging he issue. When I get the error, the lock file the error points to is empty:

_build/dev/lib/{project}/.mix/compile.lock

I can’t identify any pattern — it happens randomly and with a handful of files in the repository. Is it possible that it might have something to do with circular dependencies between modules? What can I do to better understand the error? This is the whole stack trace that I get:

You must restart your server after changing the following files:

  * _build/dev/lib/{project}/.mix/compile.lock


    (phoenix 1.7.7) lib/phoenix/code_reloader/server.ex:236: Phoenix.CodeReloader.Server.mix_compile_unless_stale_config/4
    (phoenix 1.7.7) lib/phoenix/code_reloader/server.ex:188: Phoenix.CodeReloader.Server.mix_compile/5
    (phoenix 1.7.7) lib/phoenix/code_reloader/server.ex:74: anonymous fn/4 in Phoenix.CodeReloader.Server.handle_call/3
    (phoenix 1.7.7) lib/phoenix/code_reloader/server.ex:295: Phoenix.CodeReloader.Server.proxy_io/1
    (phoenix 1.7.7) lib/phoenix/code_reloader/server.ex:72: Phoenix.CodeReloader.Server.handle_call/3
    (stdlib 5.0.1) gen_server.erl:1113: :gen_server.try_handle_call/4
    (stdlib 5.0.1) gen_server.erl:1142: :gen_server.handle_msg/6
    (stdlib 5.0.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

Hey @pepicrft details about your setup will be critical to helping you. What version of Elixir? How are you running your docker environment?

Hi @benwilson512,

I’m using Elixir 1.15.4 and Erlang/OTP 24. This happens in development, where I’m not virtualising the running of mix phx.server via solutions like Docker — Elixir and Erlang are both installed in my macOS environment (Ventura 13.4.1). Something that I noticed is that incremental builds get invalidated quite frequently, which leads to clean builds more often than expected. For example, I run mix phx.server and it launches instantly, but then I do mix test and starts compiling everything from scratch.

How can one debug issues of this nature? I wouldn’t mind sharing a copy of the project privately if that’d help diagnose the issue.

Thanks for your response :pray: