bhauman / lein-figwheel

Figwheel builds your ClojureScript code and hot loads it into the browser as you are coding!
Eclipse Public License 1.0
2.88k stars 209 forks source link

Following "Using the Figwheel REPL within NRepl" leads to "Figwheel Configuration Error" #590

Open p-himik opened 7 years ago

p-himik commented 7 years ago

Leiningen 2.7.1 lein-figwheel 0.5.12

I'm using Dirac that requires nREPL. Running both lein repl and lein figwheel consumes quite a lot of memory, so I decided to try the steps at Using the Figwheel REPL within NRepl. Everything went fine, up to a moment when I had to run (start-figwheel!). It gave me an error:

user=> (start-figwheel!)
(start-figwheel!)
Error reading Configuration

ExceptionInfo ------ Figwheel Configuration Error ------

Missing required key :cljsbuild at path []

/home/p-himik/dev/git/mga/cedar2/project.clj:48:2
  43   :less {:source-paths ["frontend/static/less"]
  44          :target-path  "frontend/static/css"
  45          :source-map   true
  46          :compression  true}
  47 
  48   :cljsbuild {:builds
       ^---  Map is missing required key: :cljsbuild
  49               {:main
  50                {:source-paths ["frontend/cljs"]
  51                 :compiler     {:main         cedar2.core
  52                                :foreign-libs [; https://github.com/zenozeng/color-hash 70a2325
  53                                               #_{:file     "frontend/static/js-inc/color-hash/color-hash.js"

------------------------------------------
  clojure.core/ex-info (core.clj:4725)

lein figwheel works fine by itself, saying Figwheel: Configuration Valid ;)

Am I missing something? Are there additional requirements for project.clj when running figwheel from inside the nREPL?

darwin commented 7 years ago

Not sure about this error. But you should definitely check this out: https://github.com/binaryage/dirac/blob/master/docs/about-repls.md#dirac--figwheel

Ideally you want Figwheel sidecar to run inside the same JVM as Dirac and make Dirac use Figwheel's compiler.

darwin commented 7 years ago

Here is the relevant config from dirac-sample project: https://github.com/binaryage/dirac-sample/blob/master/project.clj#L170-L196

p-himik commented 7 years ago

Thanks, I'll try!

But isn't it cheating in a way? It seems that I have to duplicate the build configuration inside the project configuration, that already includes the build configuration.

bhauman commented 7 years ago

This does seem odd. You may have something in your project.clj that makes it hard to read.

p-himik commented 7 years ago

@darwin Works! Thanks again. Although I don't really like duplicated info, and I can't seem to extract it to an external def. I've asked a question about it on the clojurians channel.

@bhauman I just tried to reduce my project.clj to the minimal state where the error is still reproducible, and I ended up trying the code from the guide, verbatim. The error is still there. Just in case, here's that project.clj:

(defproject repler "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.7.0"]
                 [org.clojure/clojurescript "1.7.170"]]

  :plugins [[lein-figwheel "0.5.0-1"]]

  :source-paths ["src"]

  :clean-targets ^{:protect false} ["resources/public/js" :target]

  :cljsbuild {:builds
              [{:id           "dev"
                :source-paths ["cljs_src"]
                :figwheel     true
                :compiler     {:main       repler.core
                               :asset-path "js/out"
                               :output-to  "resources/public/js/repler.js"
                               :output-dir "resources/public/js/out"}}]}
  :profiles {:dev {:dependencies [[figwheel-sidecar "0.5.8"]]
                   :source-paths ["cljs_src"]}})
bhauman commented 7 years ago

I think you make have something in your ~/.lein/profiles that is messing this up.

For a minimal case try: lein new figwheel hello lein repl => (fig-start)

p-himik commented 7 years ago
 % ls /etc/leiningen -al                      
total 20
drwxr-xr-x   2 root root  4096 Oct  5  2016 .
drwxr-xr-x 208 root root 16384 Aug  3 17:01 ..
 % ls -al ~/.lein                                                
total 20
drwxrwxr-x   3 p-himik p-himik  4096 Aug  4 21:42 .
drwxr-xr-x 166 p-himik p-himik 12288 Aug  4 21:44 ..
drwxrwxr-x   2 p-himik p-himik  4096 Aug  4 21:43 self-installs
 % lein new figwheel hello                                                    
Retrieving figwheel/lein-template/0.5.12/lein-template-0.5.12.pom from clojars
Retrieving figwheel/lein-template/0.5.12/lein-template-0.5.12.jar from clojars
Generating fresh 'lein new' figwheel project.

Change into your 'hello' directory and run 'lein figwheel'
Wait for it to finish compiling
Then open 'http://localhost:3449/index.html' in your browser
 % cd hello
 % lein repl                                                                                                                      21:54:56 2017-08-04 !10116
Retrieving lein-cljsbuild/lein-cljsbuild/1.1.7/lein-cljsbuild-1.1.7.pom from clojars
Retrieving lein-cljsbuild/lein-cljsbuild/1.1.7/lein-cljsbuild-1.1.7.jar from clojars
Retrieving org/clojure/clojurescript/1.9.854/clojurescript-1.9.854.pom from central
Retrieving com/google/javascript/closure-compiler-unshaded/v20170626/closure-compiler-unshaded-v20170626.pom from central
Retrieving com/google/javascript/closure-compiler-main/v20170626/closure-compiler-main-v20170626.pom from central
Retrieving com/google/javascript/closure-compiler-parent/v20170626/closure-compiler-parent-v20170626.pom from central
Retrieving com/google/javascript/closure-compiler-externs/v20170626/closure-compiler-externs-v20170626.pom from central
Retrieving org/clojure/tools.reader/1.0.3/tools.reader-1.0.3.pom from central
Retrieving org/clojure/tools.reader/1.0.3/tools.reader-1.0.3.jar from central
Retrieving com/google/javascript/closure-compiler-unshaded/v20170626/closure-compiler-unshaded-v20170626.jar from central
Retrieving com/google/javascript/closure-compiler-externs/v20170626/closure-compiler-externs-v20170626.jar from central
Retrieving org/clojure/clojurescript/1.9.854/clojurescript-1.9.854.jar from central
nREPL server started on port 39570 on host 127.0.0.1 - nrepl://127.0.0.1:39570
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_112-b15
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> (fig-start)
Error reading Configuration

ExceptionInfo ------ Figwheel Configuration Error ------

Missing required key :cljsbuild at path []

/home/p-himik/hello/project.clj:19:2
  14   :plugins [[lein-figwheel "0.5.12"]
  15             [lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]]]
  16 
  17   :source-paths ["src"]
  18 
  19   :cljsbuild {:builds
       ^---  Map is missing required key: :cljsbuild
  20               [{:id "dev"
  21                 :source-paths ["src"]
  22 
  23                 ;; The presence of a :figwheel configuration here
  24                 ;; will cause figwheel to inject the figwheel client

------------------------------------------
  clojure.core/ex-info (core.clj:4617)
user=>
p-himik commented 6 years ago

@bhauman I've found the cause - I have a directory /etc/leiningen. According to the documentation at https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md#declaring-profiles it should be a directory, however the code at https://github.com/bhauman/simple-lein-profile-merge/blob/master/src/simple_lein_profile_merge/core.clj#L183 tries to read it as a file. The corresponding code at https://github.com/technomancy/leiningen/blob/master/leiningen-core/src/leiningen/core/project.clj#L693 does indeed use it just as a dir, appending "profile.clj" later. This incorrect handling of global profile location leads to

{:type java.io.FileNotFoundException
   :message "/etc/leiningen (Is a directory)"
   :at [java.io.FileInputStream open0 "FileInputStream.java" -2]}]

It gets caught in https://github.com/bhauman/lein-figwheel/blob/master/sidecar/src/figwheel_sidecar/config.clj#L547 and somewhere later it's printed just as

Error reading Configuration

ExceptionInfo

without any actual info. I'm not sure why - I didn't try to dig that deep.

I obviously don't know all the history behind all involved projects, but wouldn't it make more sense to work with Leiningen folks to extract profile-related stuff to a separate library? This way there would be no code duplication, uniform behavior, and there will be one set of thorough tests.

p-himik commented 6 years ago

Another strange thing - documentation at https://github.com/bhauman/lein-figwheel/wiki/Using-the-Figwheel-REPL-within-NRepl#launching-figwheel-from-nrepl says: "no leiningen profile merging will occur". But it clearly tries to merge them! Otherwise, there would be no such error.