My home.clj was requring chess.llm, neither file had compilation issues, so I found this error below very strange and I couldn't figure it out.
user=> (require 'chess.routes.home :reload)
2026-07-10 22:09:37,296 [nREPL-session-cedf8a12-a034-475d-a72c-7683c52bca15]
Syntax error compiling at (chess/routes/home.clj:1:1).
namespace 'chess.llm' not found after loading '/chess/llm'
I even tried asking AI for help with troubleshooting but it went down the wrong paths looking for circular dependencies. It wasn't until I copied llm.clj to a different file named caca.clj while only updating the ns declaration "chess.llm => chess.caca" and corresponding requires in my home.clj, that everything loaded correctly.
It turns out that I had an empty test file test/chess/llm.clj that was somehow messing up the compilation, and removing this empty test file file, or adding a proper ns declaration, solved the issue.
I'm reporting this because it would help the next Clojure developer if the error message were more indicative of the bad test file, perhaps by including the full file path.
Here's the AI-generated explanation of this report:
Title
require yields confusing "namespace not found after loading" error if masked by empty file earlier in classpath
Environment
- Clojure Version: 1.11+ / 1.12
- Build Tool: Leiningen / Clojure CLI
Description
When attempting to require a valid Clojure namespace, if a completely empty .clj file with the exact same relative file path exists earlier in the classpath sequence (for example, in test/ when test/ precedes src/ in the active profile), Clojure throws a misleading error.
The compiler successfully locates and loads the empty file, but because the file lacks an (ns ...) declaration, it fails to find the registered namespace in memory. This effectively masks the actual, working source file further down the classpath, resulting in an error message that mistakenly implies the namespace naming is incorrect, rather than indicating a classpath prioritization issue.
Steps to Reproduce
- Create a project layout where
test/ takes priority over src/ on the classpath.
- Create a valid file at
src/chess/llm.clj containing:
`clojure
(ns chess.llm)
(defn call-llm [] :ok)
`
- Create an empty file at
test/chess/llm.clj (size 0 bytes, absolutely no content).
- Launch a REPL and evaluate:
(require 'chess.llm)
Expected Behavior
The compiler should either:
1. Skip empty files on the classpath and continue searching subsequent paths for a matching file containing a valid ns form.
2. Throw a more descriptive lifecycle error indicating which exact file path was targeted (e.g., namespace 'chess.llm' not found after loading empty file: test/chess/llm.clj).
Actual Behavior
The execution fails completely with a vague stack trace:
`clojure
Caused by: java.lang.Exception: namespace 'chess.llm' not found after loading '/chess/llm'
`