adzerk-oss / boot-cljs-repl

Boot task providing a REPL for ClojureScript development.
Eclipse Public License 1.0
72 stars 28 forks source link

"No such namespace" for ns from foreign-libs libs when eval ns-form at repl #49

Open maacl opened 7 years ago

maacl commented 7 years ago

Expected behavior

=> nil

Actual behavior

clojure.lang.ExceptionInfo: No such namespace: chrono, could not locate chrono.cljs, chrono.cljc, or Closure namespace "chrono" in file <cljs repl> {:tag :cljs/analysis-error}
    at clojure.core$ex_info.invoke(core.clj:4593)
    at cljs.analyzer$error.invoke(analyzer.cljc:610)
    at cljs.analyzer$error.invoke(analyzer.cljc:608)
    at cljs.analyzer$analyze_deps.invoke(analyzer.cljc:1708)
    at cljs.analyzer$ns_side_effects.invoke(analyzer.cljc:2559)
    at cljs.analyzer$analyze_STAR_$fn__4491.invoke(analyzer.cljc:2644)
    at clojure.lang.PersistentVector.reduce(PersistentVector.java:333)
    at clojure.core$reduce.invoke(core.clj:6518)
    at cljs.analyzer$analyze_STAR_.invoke(analyzer.cljc:2644)
    at cljs.analyzer$analyze.invoke(analyzer.cljc:2659)
    at cljs.repl$evaluate_form.invoke(repl.cljc:454)
    at cljs.repl$eval_cljs.invoke(repl.cljc:574)
    at cljs.repl$repl_STAR_$read_eval_print__8416.invoke(repl.cljc:880)
    at cljs.repl$repl_STAR_$fn__8422$fn__8431.invoke(repl.cljc:919)
    at cljs.repl$repl_STAR_$fn__8422.invoke(repl.cljc:918)
    at cljs.compiler$with_core_cljs.invoke(compiler.cljc:1154)
    at cljs.repl$repl_STAR_.invoke(repl.cljc:882)
    at cemerick.piggieback$run_cljs_repl.invoke(piggieback.clj:169)
    at clojure.lang.AFn.applyToHelper(AFn.java:171)
    at clojure.lang.AFn.applyTo(AFn.java:144)
    at clojure.core$apply.invoke(core.clj:634)
    at cemerick.piggieback$evaluate.invoke(piggieback.clj:258)
    at clojure.lang.Var.invoke(Var.java:379)
    at cemerick.piggieback$wrap_cljs_repl$fn__8909$fn__8911$fn__8912.invoke(piggieback.clj:290)
    at cemerick.piggieback$enqueue$fn__8895.invoke(piggieback.clj:246)
    at clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__1996.invoke(interruptible_eval.clj:190)
    at clojure.lang.AFn.run(AFn.java:22)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Steps to reproduce the problem

boot dev

cider-connect to nrepl created by boot or boot repl -c

(start-repl)

Switch to source buffer, C-c-v-n to eval namespace declaration or pass namespace declaration to repl.

Project compiles fine with no errors. This issue appears confined to the repl. The namespaces pm and chrono come from two javascript libs included via the foreign-libs compiler option - please see relevant parts of build-boot. If I remove the foreign-libs namespaces everything works as expected.

ns form looks as follows:

(ns app.core
  (:require-macros [hiccups.core :as hiccups :refer [html]])
  (:require [app.validation :as validation]
            [app.data :as data]
            [bouncer.core :as b]
            [pm]
            [chrono]))

build.boot contains:

(deftask dev []
  (comp (serve :dir "target/")
        (watch)
        (speak)
        (reload :on-jsload 'app.core/main)
        (cljs-repl)
        (cljs :source-map true
              :optimizations :none
              :compiler-options {:foreign-libs
                                 [{:file "src/js/prosemirror.js"
                                   :provides ["pm"]}
                                  {:file "src/js/chrono.js"
                                   :provides ["chrono"]}]
                                 :externs ["src/js/externs.js"]})
        (target :dir #{"target/"})))

Environment & Version information

CIDER version information

;; CIDER 0.14.0snapshot (package: 20160830.23)
;; Clojure 1.7.0
;; openjdk version "1.8.0_91"
;; OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
;; OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

Lein/Boot version

;; BOOT_VERSION=2.6.0

Emacs version

GNU Emacs 25.1.50.2 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9) of 2016-08-23

Operating system

Ubuntu 16.04

livtanong commented 7 years ago

Same issue for me. Additional info:

When in-nsing a namespace, all the locally declared vars are available, but anything else that is brought in by (:require ...) in that namespace (like cljs-time) cannot be found. It's as if (:require ...) never happened. I can, however manually (require '[cljs-time.core :as t]) in the repl and it will then be available.

darkleaf commented 7 years ago

I have the same problem. Do you found solution for this issue?

livtanong commented 7 years ago

I switched to Neovim. :P

plexus commented 6 years ago

We eventually figured this out. This problem occurs when boot-cljs-repl doesn't get the same compiler options that your main build gets.

To fix this you need to be on 0.4.0-SNAPSHOT (or current master) as before that there's no way to pass options through to Weasel -> Piggieback -> cljs.repl.

If you're using the right version you can pass the options into start-repl with :cljs-repl-opts. We ended up with something like this.

(require
 '[adzerk.boot-cljs            :refer [cljs]]
 '[adzerk.boot-cljs-repl       :refer [cljs-repl] :as boot-cljs-repl]
 '[clojure.edn]
  ,,,)

(defn read-edn-file
  "Slurp and parse an EDN file"
  [path]
  (-> path slurp clojure.edn/read-string))

(defn start-repl
  "Start a browser connected REPL (Weasel). Like boot-cljs-repl/start-repl but
  passes on the compiler options from the given .cljs.edn file."
  []
  (boot-cljs-repl/start-repl :cljs-repl-opts
                             (:compiler-options (read-edn-file "path/to/build.cljs.edn"))))