Fork me on GitHub
#shadow-cljs
<
2017-10-03
>
mhuebert00:10:21

I’m trying to get a project building with shadow-cljs, and running into a problem compiling tools.reader:

mhuebert00:10:29

failed to compile resource: [:shadow.build.classpath/resource "cljs/tools/reader/reader_types.cljs"]
{:tag :shadow.build.compiler/compile-cljs, :source-id [:shadow.build.classpath/resource "cljs/tools/reader/reader_types.cljs"], :url #object[java.net.URL 0x2be3d771 "jar:file:/Users/MattPro/.m2/repository/org/clojure/tools.reader/1.0.5/tools.reader-1.0.5.jar!/cljs/tools/reader/reader_types.cljs"], :file nil, :line 43, :column 1, :source-excerpt {:start-idx 38, :before [";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" ";; reader deftypes" ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" ""], :line "(deftype StringReader", :after ["    [s s-len ^:mutable s-pos]" "  Reader" "  (read-char [reader]" "    (when (> s-len s-pos)" "      (let [r (.charAt s s-pos)]"]}}
ExceptionInfo: failed to compile resource: [:shadow.build.classpath/resource "cljs/tools/reader/reader_types.cljs"]
...
Caused by:
ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to java.lang.String
	clojure.core/symbol (core.clj:579)
	clojure.core/symbol (core.clj:574)
	cljs.analyzer/dep-has-global-exports? (analyzer.cljc:763)
	cljs.analyzer/dep-has-global-exports? (analyzer.cljc:759)

mhuebert00:10:20

in shadow.cljs is [org.clojure/tools.reader "1.0.5"]

mhuebert00:10:08

shadow-cljs version 2.0.6

thheller07:10:51

@mhuebert very confusing error, not sure how it ends up on that path. it compiles fine for me. might be a case of broken metadata which causes it to report the wrong location. will look into it

thheller09:10:57

no idea what could cause this.

thheller09:10:27

just released 2.0.7 which bumps the clj(s) versions, should not affect that error but who knows

mhuebert10:10:53

@thheller is there any equivalent of lein clean to try in a case like this?

mhuebert10:10:45

other than just removing the out directory

mhuebert10:10:31

tried with 2.0.7 and deleted tools.reader from my repository (to fetch again) and deleted the target folder. same error, but much nicer formatting. agree it is very weird.

File: nil
--------------------------------------------------------------------------------
...
  42 |
  43 | (deftype StringReader
-------^------------------------------------------------------------------------
  44 |     [s s-len ^:mutable s-pos]
  ...
--------------------------------------------------------------------------------
ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to java.lang.String
	clojure.core/symbol (core.clj:579)
	clojure.core/symbol (core.clj:574)
	cljs.analyzer/dep-has-global-exports? (analyzer.cljc:763)

mhuebert10:10:41

i believe i require these as clojure.tools.reader (w/o reader conditionals), could the aliasing have anything to do with it?

thheller10:10:48

I fixed the error format, guess I missed the File: nil 😉

thheller10:10:57

shouldn’t have anything to do with the aliasing but might

thheller10:10:02

I’ll check that

mhuebert10:10:36

after switching all the tools.reader requires to reader conditionals, I get a different error, related to “cljs.repl” and ‘Unable to find static field: INFERRED_CONST_CHECKS’, full stacktrace: https://gist.github.com/mhuebert/263433cd01df6053f237d9671c3c6e41

thheller10:10:57

[clojure.tools.reader.reader-types :as read]

thheller10:10:49

hmm weird, do you import cljs.closure somewhere?

thheller10:10:00

I made sure to never import that anywhere

thheller10:10:26

do you use shadow-cljs standalone or embedded in lein or boot?

thheller10:10:20

ah wait cljs.repl requires cljs.closure

thheller10:10:44

the weird thing is that I can compile everything just fine

thheller10:10:55

maybe some weird AOT artifact

thheller10:10:12

can you delete target/shadow-cljs completely and restart the shadow-cljs process?

mhuebert10:10:14

have you tried compiling with a require to `[clojure.tools.reader.reader-types] (instead of cljs.tools.reader)?

thheller10:10:27

[clojure.tools.reader.reader-types :as read]
            [cljs.repl :as r]

mhuebert10:10:30

tried deleting target & recompile, same thing

thheller10:10:33

compiled just fine

thheller10:10:49

what are your :dependencies? maybe there is an old version of closure in there somehow?

thheller10:10:53

try starting shadow-cljs clj-repl and then (require 'cljs.repl)

thheller11:10:00

that should not fail

mhuebert11:10:07

does shadow-cljs have a way to print the dep tree

thheller11:10:14

shadow-cljs --cli-info

mhuebert11:10:35

so that fails for me

thheller11:10:38

not a proper tree but it lists dependencies

mhuebert11:10:39

mattpro:editor MattPro$ shadow-cljs clj-repl
shadow-cljs - config: /Users/MattPro/Documents/sites2017/maria/editor/shadow-cljs.edn version: 2.0.7
shadow-cljs - starting ...
WARNING: boolean? already refers to: #'clojure.core/boolean? in namespace: clojure.tools.analyzer.utils, being replaced by: #'clojure.tools.analyzer.utils/boolean?
WARNING: boolean? already refers to: #'clojure.core/boolean? in namespace: clojure.tools.analyzer, being replaced by: #'clojure.tools.analyzer.utils/boolean?
shadow-cljs - server running at 
shadow-cljs - socket repl running at localhost:62834
shadow-cljs - nrepl running at localhost/127.0.0.1:62836
shadow-cljs - REPL - see (help), :repl/quit to exit
[1:0]~shadow.user=> (require 'cljs.repl)
CompilerException java.lang.RuntimeException: Unable to find static field: INFERRED_CONST_CHECKS in class com.google.javascript.jscomp.DiagnosticGroups, compiling:(cljs/closure.clj:100:1)

thheller11:10:22

what the heck … those boolean? warnings shouldn’t be there

mhuebert11:10:31

in .lein/profiles.clj i have [lein-count "1.0.2"] [lein-clojars "0.9.1"] [lein-release "1.0.6"]

thheller11:10:12

[zilence@zpro ~/code/tmp/weird]$ shadow-cljs init
shadow-cljs - init
- /Users/zilence/code/tmp/weird/shadow-cljs.edn
Create? [y/n]: y
shadow-cljs - created default configuration
[zilence@zpro ~/code/tmp/weird]$
[zilence@zpro ~/code/tmp/weird]$ shadow-cljs clj-repl
shadow-cljs - config: /Users/zilence/code/tmp/weird/shadow-cljs.edn version: 2.0.7
shadow-cljs - updating dependencies
Retrieving thheller/shadow-cljs/2.0.7/shadow-cljs-2.0.7.pom from 
Retrieving thheller/shadow-cljs/2.0.7/shadow-cljs-2.0.7.jar from 
shadow-cljs - dependencies updated
shadow-cljs - re-building aot cache on startup, that will take some time.
shadow-cljs - starting ...
shadow-cljs - server running at 
shadow-cljs - socket repl running at localhost:52062
shadow-cljs - nrepl running at localhost/127.0.0.1:52064
shadow-cljs - REPL - see (help), :repl/quit to exit
[1:0]~shadow.user=> (require 'cljs.repl)
nil
[1:0]~shadow.user=>

thheller11:10:33

thats how it supposed to look

mhuebert11:10:47

those boolean? warnings appear on my system no matter what tooling i use, and am unsure of why, even if i comment everything out in .lein/profiles

thheller11:10:00

.lein/profiles doesn’t affect shadow-cljs

thheller11:10:14

can you paste shadow-cljs --cli-info?

thheller11:10:33

only thing I can think of is deps conflict

thheller11:10:02

[maven] org/clojure/clojurescript/1.9.854/clojurescript-1.9.854.jar how does that get there

thheller11:10:19

do you have it in :dependencies?

mhuebert11:10:21

sorry i was going to paste that earlier.

thheller11:10:57

please remove that. forgot to guard against that.

mhuebert11:10:15

ah ok. i had an error with the clojure dependency but not cljs, hence i thought cljs was required

thheller11:10:19

its fine in theory but there were some breaking changes in CLJS+Closure recently

mhuebert11:10:37

[1:0]~shadow.user=> (require 'cljs.repl)
CompilerException java.lang.RuntimeException: No such var: util/normalize-path, compiling:(cljs/closure.clj:1601:22)

thheller11:10:50

that might be AOT now

thheller11:10:03

delete target/shadow-cljs just to be safe

mhuebert11:10:05

ok i’ll clear it out

mhuebert11:10:19

i still wonder why i get these WARNING‘s about boolean?.

mhuebert11:10:43

ok requiring ‘cljs.repl works now

mhuebert11:10:57

going to try compiling the project again

mhuebert11:10:18

cljs/core.cljs [line 988, col 14] No reader function for tag Inf.
{:type :reader-exception, :ex-kind :reader-error, :file "cljs/core.cljs", :line 988, :col 14}
ExceptionInfo: cljs/core.cljs [line 988, col 14] No reader function for tag Inf.

thheller11:10:11

hmm maybe tools.reader in your :dependencies still?

thheller11:10:37

I really need to make the whole dependencies resolution more robust

mhuebert11:10:51

is the latest tools.reader included automatically? i need it for my app

thheller11:10:05

CLJS always ships with tools.reader

thheller11:10:26

1.1.0 is the latest version that fixes the Inf issue above

mhuebert11:10:57

ah ok, i need to remove it from a bunch of things in my project then

thheller11:10:48

ok the problem is that shadow-cljs already depends on those things but if you declare them in :dependencies they overwrite the version that shadow-cljs wants

thheller11:10:05

I need to fix that or at least warn

mhuebert11:10:47

so shadow-cljs will ignore the project.clj in the current directory but still use the deps listed in the dependencies

mhuebert11:10:14

somewhere i have tools.reader-1.0.3 in clj-info

thheller11:10:28

shadow-cljs does not use lein in any way unless you tell it to

thheller11:10:37

so project.clj might as well not exist

thheller11:10:10

deps only whats listed in :dependencies in shadow-cljs.edn

mhuebert11:10:23

i mean transitive deps

thheller11:10:05

Not sure what you mean? it uses the same lib that lein uses to resolve dependencies, so the same rules apply

thheller11:10:21

in theory the tools.reader dep of shadow-cljs should be chosen since its 1.1.0

mhuebert11:10:32

i mean somewhere in a transitive dependency of my project, an old version of tools.reader is included, [maven] org/clojure/tools.reader/1.0.3/tools.reader-1.0.3.jar

mhuebert11:10:54

it shows up when i run --cli-info and I am guessing that’s why i am still getting the Inf error

thheller11:10:16

ah ok. yes thats the source of the Inf error

mhuebert11:10:30

but i am not sure yet where it is being included

thheller11:10:38

can you give me your :dependencies so I can track this down properly?

mhuebert11:10:12

i have a bunch of local libs unfortunately which might make that complicated because i’ve been makign changes to them during this debugging process so there are a bunch of undeployed snapshots

mhuebert11:10:39

is there a way to see a tree of dependencies / see where a particular dep is coming from?

thheller11:10:49

ah ok, you could try lein deps :tree if you have a project.clj anyways

thheller11:10:21

no but I will definitely add the tree visualizer, the flat list is kinda useless

thheller11:10:02

easy fix would be to just add [org.clojure/tools.reader "1.1.0"] to your deps (I think)

mhuebert11:10:58

so the only place 1.0.3 from tools.reader exists is in cljs 1.9.854

mhuebert11:10:17

which is listed in several project.clj‘s of my dependencies

thheller11:10:54

does it still list 1.9.854 in --cli-info?

thheller11:10:22

I might be wrong in my understanding of how maven resolves dependency conflicts

mhuebert11:10:39

no, it lists 1.9.946

mhuebert11:10:07

but i added [org.clojure/tools.reader "1.1.0"] to shadow-cljs.edn

thheller11:10:09

btw libraries should always use [org.clojure/clojurescript "1.9.854" :scope :provided]

mhuebert12:10:10

@thheller tiny correction, should be :scope "provided"

mhuebert11:10:14

and that didn’t change

mhuebert11:10:25

ah ok, i didn’t know that

thheller11:10:37

try deleting the AOT cache

thheller11:10:08

I’m regretting a bit that I relaxed the AOT compiler to only recompile when the shadow-cljs version changes

thheller11:10:26

mistakingly assumed that would be enough 😛

mhuebert11:10:29

maybe whenever deps change

thheller11:10:59

it was whenever deps changed but it doesn’t really need to re-compile AOT when you change the version of a CLJS lib

mhuebert11:10:02

i like how fast shadow-cljs usually give me feedback. more errors, earlier, than other tools i’ve used

thheller11:10:26

I don’t like that the errors are so hard to track though 😉

mhuebert11:10:46

ok, it is building, just a warning from transit

------ WARNING #1 --------------------------------------------------------------
 File: :332:1
--------------------------------------------------------------------------------
 328 |   "Construct a URI from a string."
 329 |   [s]
 330 |   (ty/uri s))
 331 |
 332 | (defn uri?
-------^------------------------------------------------------------------------
 uri? already refers to: cljs.core/uri? being replaced by: cognitect.transit/uri?
--------------------------------------------------------------------------------
 333 |   "Returns true if x is a transit URI value, false otherwise."
 334 |   [x]
 335 |   (ty/isURI x))
 336 |
 337 | (defn uuid
--------------------------------------------------------------------------------

thheller11:10:04

old transit version probably 😛

thheller11:10:21

why the heck is File: always empty, I need to fix that

thheller11:10:12

ah found it

mhuebert11:10:49

ah.. goog.require could not find: cljs.core$macros

mhuebert11:10:55

maybe this is related to self-host stuff

thheller11:10:06

yeah I still didn’t get to that

thheller11:10:17

not the slightest idea how self host works

thheller11:10:31

what do you use it for?

thheller11:10:40

let me check, maybe its just a property I forgot to set

mhuebert11:10:25

so in the existing (non-shadow) build, window.cljs.core$macros is there, missing here

thheller11:10:08

yeah I don’t compile the self hosted stuff properly

thheller11:10:41

that just adds the dep, need to find where it compiles the macros

thheller11:10:06

(ns cljs.js
  (:refer-clojure :exclude [require])
  (:require-macros [cljs.js :refer [dump-core]]
                   [cljs.env.macros :as env])
  (:require [clojure.string :as string]
            [clojure.walk :as walk]
            [cljs.env :as env]
            [cljs.spec.alpha]
            [cljs.analyzer :as ana]
            [cljs.compiler :as comp]
            [cljs.tools.reader :as r]
            [cljs.tools.reader.reader-types :as rt]
            [cljs.tagged-literals :as tags]
            [goog.crypt.base64 :as base64]
            [cljs.source-map :as sm])
  (:import [goog.string StringBuffer]))

(js/goog.require "cljs.core$macros")

thheller11:10:10

this is just plain weird 😛

mhuebert11:10:23

last time I talked to dnolen about this he said that core$macros are handled as a special case, other macro files are not compiled, you have to provide them manually (which is a big PITA)

mhuebert11:10:31

and yes, weird!

thheller11:10:22

still trying to figure out where exactly it gets compiled, there a whole lot of special cases for cljs.core$macros

thheller11:10:59

had hoped for a cljs.compiler.api/compile-macro-ns or so 🙂

mhuebert11:10:05

yeah! that would be nice. there is the jira issue: https://dev.clojure.org/jira/browse/CLJS-2270

mhuebert11:10:41

so there is openness to improving it

thheller12:10:09

Not enough time but I will look into it later today https://github.com/thheller/shadow-cljs/issues/103

thheller12:10:40

It should not be hard, found a :macro-ns option that seems to control it

thheller12:10:09

just a bunch of special cases in the code I don’t quite understand yet

mhuebert12:10:13

ok. i realize this may be a messy thing. if we can get it working i would be very happy to use shadow-cljs for all of Maria’s builds, i really prefer it in the small cases i’ve tried

thheller12:10:53

I definitely want to support this use case. It just scares me since I don’t really understand how self host works 🙂

mhuebert12:10:07

plus i could probably use shadow-cljs to do the AOT macro compiles 🙂

thheller12:10:13

makes my head hurt just thinking about it 🙂

thheller12:10:45

if I figure out how to compile cljs.core it should be easy to extend it to others as well

mhuebert12:10:58

yeah, this stuff is annoying.

ivanpierre14:10:38

Feedback from my tests, definitively shadow is nice for node + electron... perhaps doc 😉 need help ?

ivanpierre14:10:33

I looked on the lumo integration as repl, seems tedious. I have to look more on the whole ecosystem... coming from clojure.... 😉

ivanpierre16:10:57

But I have to put it on wheels with boot and lein. Big problems with boot pods that wipe the whole directory, hard to put your main.js in root of the project... well, not hard, but you loose the whole thing after compile 😄

richiardiandrea16:10:52

@ivanpierre there has been some discussion about lumo repl integration in the lumo channel...I am very fond of the Language Server Protocol for that also seeing it is now supported everywhere but I haven't got around to doing it

thheller20:10:59

@mhuebert can you give a minimal example cljs.js snippet so I can test if it works?

thheller20:10:15

I have never used it before and don’t know how to verify if the macro compile worked

thheller20:10:26

nevermind found one

mhuebert22:10:52

sorry just saw this now