Skip to content

Instantly share code, notes, and snippets.

@olivergeorge
Last active May 15, 2020
Embed
What would you like to do?
REPL not considering namespace aliases if pre-compiled

Setup is based on clojurescript getting started guide. I've added a require statement to the core ns and using the latest master sha

deps.edn

{:deps {org.clojure/clojurescript {:git/url "https://github.com/clojure/clojurescript.git"
                                   :sha "ec0fc33030ae1858a29c52f38e81fba4180d492b"}}}

src/hello_world/core.cljs

(ns hello-world.core
  (:require [goog.object :as gobj]))

Test 1

We can compile and run the repl in one step and see the aliases resolving.

rm -rf .cpcache out

clj -m cljs.main -co '{:main hello-world.core}' -c -r
ClojureScript 0.0.630944134
cljs.user=> (in-ns 'hello-world.core)
nil
hello-world.core=> (gobj/get #js{:a 1} "a")
1

Test 2

But we can break it by doing compile before running the repl

rm -rf .cpcache out

clj -m cljs.main -co '{:main hello-world.core}' -c 

clj -m cljs.main -co '{:main hello-world.core}' -r
ClojureScript 0.0.630944134
cljs.user=> (in-ns 'hello-world.core)
nil
hello-world.core=> (gobj/get #js{:a 1} "a")
WARNING: No such namespace: gobj, could not locate gobj.cljs, gobj.cljc, or JavaScript source providing "gobj" at line 1 <cljs repl>
WARNING: Use of undeclared Var gobj/get at line 1 <cljs repl>
Execution error (ReferenceError) at (<cljs repl>:1).
gobj is not defined

Test 3

You can workaround the problem by setting :analyze-path

rm -rf .cpcache out

clj -m cljs.main -co '{:main hello-world.core}' -c 

clj -m cljs.main -co '{:main hello-world.core :analyze-path ["src"]}' -r
ClojureScript 0.0.630944134
cljs.user=> (in-ns 'hello-world.core)
nil
hello-world.core=> (gobj/get #js{:a 1} "a")
1

NOTES: Adding -c to the repl lines doesn't help if it's already compiled. Presumably that's skipping the analysis work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment