Search code examples
clojureclojurescriptcore.asyncboot-clj

simple boot project not working with cljs and async


I have a very simple project. I created the simplest ever project with boot and cljs. It compiled successfully and I was able to see the correct log in the html. When I added a basic support for async I got the message:

No such namespace: clojure.core.async, could not locate clojure/core/async.cljs, clojure/core/async.cljc, or Closure namespace "clojure.core.async"

The project has just the following structure:

exemplo_cljs
    html
       index.html
    src
       exemplo_cljs
           core.cljs
    build.boot

The contents of index.html:

<!doctype html>
<html lang="en">
    <head>
        <title>Hello</title>
    </head>
    <body>
        <h2>Hello</h2>
        <script src="main.js"></script>
    </body>
</html>

core.cljs

(ns exemplo-cljs.core
  (:require [clojure.core.async :as async]))

(def exercise (async/chan))

;; enable cljs to print to the JS console of the browser
(enable-console-print!)

;; print to the console
(println "Hello, World 4!")

and build.boot

(set-env!
 :source-paths #{"src"}
 :resource-paths #{"html"}

 :dependencies '[[adzerk/boot-cljs "1.7.170-3"]
                 [org.clojure/core.async "0.2.371"]])

(require '[adzerk.boot-cljs :refer [cljs]])

The original working project had the same basic structure except for the require and def of a channel in the core.cljs file and the dependency added in the build.boot


Solution

  • That's because in ClojureScript, core.async lives under cljs.core.async rather than clojure.core.async.

    So you just need to change your ns form to:

    (ns exemplo-cljs.core
      (:require [cljs.core.async :as async]))