You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

首次运行ClojureScript遇报错:无法定位cljs/main.clj

解决ClojureScript启动Repl时的FileNotFoundException错误

Hey there! As a fellow Clojure(Script) enthusiast, I’ve run into this exact issue when I was starting out too—let’s get you sorted.

为什么会出现这个错误?

The error Could not locate cljs/main__init.class or cljs/main.clj on classpath basically means your project’s classpath doesn’t include the ClojureScript library. When you run clj --main cljs.main, the Clojure CLI can’t find the necessary code to bootstrap the ClojureScript repl because the dependency is missing.

快速解决方案

Here are the steps to fix this, depending on how you set up your project:

1. 如果使用deps.edn(Clojure CLI工具)

  • First, make sure you’re in your project’s root directory. If you don’t have a deps.edn file there yet, create one with this content:
    {:deps {org.clojure/clojurescript {:mvn/version "1.11.60"}}}
    
    (You can replace the version number with the latest stable release if you want—1.11.60 is a solid, well-tested pick.)
  • Now re-run your original command:
    clj --main cljs.main --compile hello-world.core --repl
    
    The CLI will pull down the ClojureScript dependency automatically and find cljs.main this time.

2. 临时测试(不需要修改配置文件)

If you want to verify this is the issue without creating/editing deps.edn, run this one-liner to temporarily add the ClojureScript dependency to your classpath:

clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.11.60"}}}' --main cljs.main --repl

If this starts the repl successfully, you know the problem was missing dependencies—just go ahead and set up the deps.edn file for your project to make it permanent.

3. 如果使用Leiningen(lein)

If you followed a tutorial that uses Leiningen instead of the Clojure CLI, make sure your project.clj includes the ClojureScript dependency in the :dependencies vector:

(defproject hello-world "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.11.1"]
                 [org.clojure/clojurescript "1.11.60"]]
  ;; ... other configs like :cljsbuild if needed
)

Run lein deps to pull the dependency, then you can start the repl with lein cljs repl (or use your original command if you have the right setup).

额外提醒

Double-check that you’re running the command from your project’s root directory—if you’re in a subfolder, the Clojure CLI won’t pick up your deps.edn file, leading to the same missing dependency error.

Give these steps a shot, and you’ll be writing ClojureScript in no time!

内容的提问来源于stack exchange,提问作者user9714947

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:21:45