No config found for file... Try calling `dune build`

For posterity, hoping somebody in the future finds this when they hit the same problem:

I just spent a painful ~hour trying to figure out why emacs wasn’t happy with my .ml files in a new project. I got this message in emacs when my cursor was on the first line of one of the first source files I added:

No config found for file "" in "model/bin". Try calling `dune build`.

Turns out I had to kill a running ocamlmerlin-server process, and possibly restart emacs (I did have to restart because merlin stopped working in emacs completely, possibly because of some separate problem). I wasn’t really conscious of this global state.

I suspect I got myself into this pickle by copying an existing project to set up a new project. I had changed library names in dune files but had not renamed my new .opam file. On the other hand, killing ocamlmerlin-server and restarting emacs without fixing that seems to have fixed merlin in both the old and new projects.

I’m trying to think what would have helped here. Probably in these days of LSP servers I should have thought earlier to look for a process to kill, but not knowing dune etc. well still there were a lot of other things I tried first. I think posting this may be the only change needed!

I’m not sure if this would have helped in your particular situation, but whenever I run into these kinds of merlin issues (which is fairly rarely, and usually due to copying between projects), I first try and run merlin-stop-server from within Emacs first which usually fixes the problem.