Fork me on GitHub
#shadow-cljs
<
2020-08-16
>
thheller09:08:05

@pavel.klavik yeah you should check what the message looks like it is sending. its transit but that is somewhat readable. in the chrome devtools network tab select the websocket connection going to ....

thheller09:08:48

that has a "Messages" tab. the message with the error is likely with a green background (sent to server) and starts with ["^ ", "~:op", "~:obj-result", ...

Pavel Klavík15:08:01

I send there two strings, one "test" which works fine, the other "čau" which fails and I get the following:

Pavel Klavík15:08:09

The difference I see for the second case is that it also sends this at the end:

thheller16:08:56

hmm ok there is definitely something broken coming. if you look at the :cljs-eval message the code is definitely garbled

thheller16:08:22

weird how it turns into the proper thing a bit later. so I suppose there is some encoding going on somewhere

thheller16:08:39

can the check the cljs-compile-result message what the :js code looks like? it is cut off in the screenshot

thheller16:08:08

also check sending the same thing from the terminal. wonder if it shows up garbled as well.

Pavel Klavík16:08:34

This is what I get when running "čau" in shadow-cljs cljs-repl:

Pavel Klavík18:08:17

@U05224H0W ^^ (not sure whether you saw my reply)

thheller18:08:46

I do. just no clue whats going on on your machine. I just get the regular "čau" as expected. no garbled text or weird encodings.

thheller18:08:20

I'm also on windows so its not that

thheller18:08:58

I have no idea what is happening but it seems to start with receiving bad input from the REPL

Pavel Klavík19:08:36

Also it was not happening till recently. Not sure how long because I haven't tested it for some time. Maybe somehow related to updating Windows or updating of Cursive, not sure. But I haven't update Windows on my laptop and it was broken and it didn't fix with both updating Windows and IntelliJ with Cursive.

Pavel Klavík19:08:17

Maybe @U0567Q30W will have some idea how to debug Cursive?

thheller19:08:03

doesn't seem to be related to Cursive since the cljs-repl input is also bad. bad in a different way but still incorrect.

Pavel Klavík20:08:34

that might be related to something I noticed in general that Unicode characters are displayed broken in REPL, even on my server REPL

Pavel Klavík20:08:04

but not sure whether it also influences input there

thheller20:08:27

I don't have any ideas what might be causing this

thheller20:08:32

how do you start shadow-cljs?

thheller20:08:15

does npx create-cljs-project foo cd foo npx shadow-cljs node-repl work?

Pavel Klavík20:08:37

@U05224H0W I am running it using shadow-cljs watch client . This works when I send "čau" from Cursive.

thheller20:08:40

by "This works" you mean the empty project works but yours doesn't?

Pavel Klavík20:08:47

No, node-repl work for both. It just runs Clojure? Or how can I switch to Clojurescript?

Pavel Klavík20:08:20

I also tested another very simple project I made using Shadow-cljs and it is failing the same, so it is not something we changed in our project recently.

thheller20:08:23

I'm confused. what are you asking me here?

thheller20:08:49

> It just runs Clojure?

Pavel Klavík20:08:09

When I run node-repl, what does it connect to? As I understand it, (shadow/repl :client) switches to ClojureScript REPL for the particular client.

thheller20:08:54

(shadow/repl :client) switches to the REPL of the :client build. whatever JS runtime is connected to that

thheller20:08:26

I'm entirely confused what you are doing here now

thheller20:08:18

I cannot help you if you only give me half the information about what you are doing.

thheller20:08:27

what is the above screenshot from?

Pavel Klavík20:08:15

Sorry, I will try to explain better. I tested running shadow-cljs node-repl on my project. I connect to the REPL from Cursive and it works as above.

thheller20:08:33

no it does not!

thheller20:08:54

you seem to misunderstand how all this works

Pavel Klavík20:08:11

ok, so how does it work?

thheller20:08:15

above you send (shadow/repl :client). it will attempt to switch to the REPL of the client build

thheller20:08:27

it is telling you that build is not running and does NOT switch

thheller20:08:40

therefore you are just still in CLJ and that works fine

Pavel Klavík20:08:53

ya, still makes sense

thheller20:08:06

so you want to switch to the node-repl inside cursive

thheller20:08:49

you do that by running (shadow/node-repl) or (shadow/repl :node-repl) in case you already have done shadow-cljs node-repl

thheller20:08:21

do not just ignore error messages please ... they are there for a reason.

Pavel Klavík20:08:01

ya, I get that, just was not sure what node-repl means or how I should switch to it

Pavel Klavík20:08:16

it fails the same:

thheller20:08:08

ok, so same problem.

thheller20:08:20

now please do the same in the empty project I asked you to create

thheller20:08:50

I want to establish if this has something to do with your project setup or not

Pavel Klavík20:08:54

sure, working on it

Pavel Klavík20:08:45

still the same problem

thheller20:08:13

ok sorry. then I have absolutely no clue what the problem is.

Pavel Klavík20:08:48

it is a puzzle, no idea what is going on

thheller20:08:27

you can maybe try going back version by version until it works but I suspect it starts failing when I switched the transport to use transit instead of EDN

Pavel Klavík20:08:30

in the worst case, I can avoid using non-ASCII characters in my development data so I can run them in REPL without any problems

Pavel Klavík20:08:49

which version is it?

thheller20:08:02

but I don't have any issues with any unicode data at all

Pavel Klavík20:08:29

that is one thing I did, I was using npm install -g shadow-cljs to run the binary directly, and I had a quite old binary for some time

thheller20:08:32

no clue. probably 2.10.0

Pavel Klavík20:08:47

and recently, I updated it on both devices with npm update -g shadow-cljs

thheller20:08:50

I do hope that you have shadow-cljs installed in the project directly. the global install really doesn't matter all that much then and doesn't have anything to do with this anyways.

Pavel Klavík20:08:13

I have shadow-cljs as dependency in both project.clj and package.json, but I noticed that there was outdated version of Shadow-cljs displayed on the start when running shadow-cljs watch client, so I tried to update it in this way

thheller20:08:11

well yes the versions should be somewhat close to each other. if you want to avoid guessing remove the global install completely

thheller20:08:26

although you have to run npx shadow-cljs instead of shadow-cljs then so kinda annoying 😛

Pavel Klavík20:08:33

I am getting this output:

C:\Shared\orgpad>shadow-cljs watch client
------------------------------------------------------------------------------
shadow-cljs - config: C:\Shared\orgpad\shadow-cljs.edn
shadow-cljs - socket connect failed, server process dead?
NPM dependency "react" has installed version "^16.13.1"
"16.13.0" was required by jar:file:/C:/Users/pavel/.m2/repository/reagent/reagent/0.10.0/reagent-0.10.0.jar!/deps.cljs
NPM dependency "react-dom" has installed version "^16.13.1"
"16.13.0" was required by jar:file:/C:/Users/pavel/.m2/repository/reagent/reagent/0.10.0/reagent-0.10.0.jar!/deps.cljs
shadow-cljs - HTTP server available at 
shadow-cljs - HTTP server available at 
shadow-cljs - server version: 2.10.14 running at 
shadow-cljs - nREPL server started on port 9000
shadow-cljs - watching build :client
[:client] Configuring build.
[:client] Compiling ...
[:client] Build completed. (934 files, 79 compiled, 0 warnings, 29.43s)
while having this in project.clj
[thheller/shadow-cljs "2.10.18"]

thheller20:08:03

that can't be

thheller20:08:09

> shadow-cljs - server version: 2.10.14

thheller20:08:52

whats your shadow-cljs.edn?

thheller20:08:07

I assume you have :lein true or so in there?

thheller20:08:50

something is very weird ... this extra garbage --------------- line shouldn't be there anymore. I fixed that.

Pavel Klavík20:08:18

no, I didn't use that, I have ClojureScript dependencies written twice, once in project.clj for Cursive, and once for Shadow-cljs

thheller20:08:20

it looks like you do not have :lein true in your shadow-cljs.edn?

Pavel Klavík20:08:42

{:source-paths ["src"]
 :dependencies [[reagent "0.10.0"]
                [reagent-utils "0.3.3"]
                [re-frame "0.12.0"]
                [com.cognitect/transit-cljs "0.8.264"]
                [day8.re-frame/http-fx "v0.2.0"]
                [hickory "0.7.1"]
                [binaryage/devtools "0.9.10"]
                [bidi "2.1.6"]
                [com.taoensso/sente "1.15.0"]
                [venantius/accountant "0.2.5"]
                [com.cemerick/url "0.1.2-SNAPSHOT"]
                [com.taoensso/timbre "4.10.0"]
                [cljc.java-time "0.1.8"]
                [bouncer "1.0.1"]
                [orgpad/volcano "0.1.2"]
                [macchiato/core "0.2.17"]
                [macchiato/env "0.0.6"]
                [mount "0.1.16"]]
 :nrepl        {:port 9000}
 :builds       {:client     {:target           :browser
                             :output-dir       "resources/public/js/compiled"
                             :asset-path       "/js/compiled"
                             :modules          {:shared {:entries []}
                                                :main   {:init-fn    orgpad.client.core/init
                                                         :depends-on #{:shared}}
                                                :layout {:entries    [orgpad.client.layout.webworker.core]
                                                         :depends-on #{:shared}
                                                         :web-worker true}}
                             :compiler-options {:infer-externs      :auto
                                                :output-feature-set :es6}
                             :devtools         {:after-load     orgpad.client.core/mount-root
                                                :before-load    orgpad.client.core/stop-web-workers
                                                :watch-dir      "resources/public"
                                                :browser-inject :main
                                                :loader-mode    :script}}
                :landing    {:target     :browser
                             :output-dir "landing/resources/js"
                             :asset-path "/js"
                             :modules    {:main {:init-fn orgpad.landing.dev/init}}
                             :devtools   {:http-root      "landing/resources"
                                          :http-port      3500
                                          :after-load     orgpad.landing.dev/mount-root
                                          :watch-dir      "landing/resources"
                                          :browser-inject :main}}
                :emails     {:target     :browser
                             :output-dir "emails/js"
                             :asset-path "/js"
                             :modules    {:main {:init-fn orgpad.server.email.dev/init}}
                             :devtools   {:http-root      "emails"
                                          :http-port      3600
                                          :after-load     orgpad.server.email.dev/mount-root
                                          :watch-dir      "emails"
                                          :browser-inject :main}}
                :screenshot {:target           :node-script
                             :main             orgpad.screenshot.core/main
                             :output-to        "screenshot/screenshot.js"
                             :devtools         {:autoload true}
                             :compiler-options {:optimizations :simple}}}}

thheller20:08:48

ah ok. then it doesn't matter what you put in project.clj at all as far as shadow-cljs is concerned

thheller20:08:18

then the version you have in package.json matters

Pavel Klavík20:08:30

I see, so I could remove it? And how is the version in package.json used?

thheller20:08:33

or just add :version "2.10.21" to your shadow-cljs.edn

thheller20:08:57

I don't understand that question

Pavel Klavík20:08:29

Suppose that I want to update to 10.21. I go and change it in package.json.

Pavel Klavík20:08:43

How does it propagates? Do I need to update global shadow-cljs as well?

thheller20:08:47

you basically never edit package.json by hand

thheller20:08:07

if you do you need to run npm install afterwards

thheller20:08:38

you can declare the version you want in shadow-cljs.edn as mentioned above if that helps

thheller20:08:03

npm install shadow-cljs also updates it

thheller20:08:17

but if you edit you manually need to run npm install afterwards

Pavel Klavík20:08:50

ok, that is what I was always doing

thheller20:08:39

it makes sense to keep the global install somewhat on the same level but if you want to be totally sure use npx shadow-cljs instead

Pavel Klavík20:08:54

So I updated both to 10.21:

C:\Shared\orgpad>shadow-cljs watch client
shadow-cljs - config: C:\Shared\orgpad\shadow-cljs.edn
shadow-cljs - socket connect failed, server process dead?
NPM dependency "react" has installed version "^16.13.1"
"16.13.0" was required by jar:file:/C:/Users/pavel/.m2/repository/reagent/reagent/0.10.0/reagent-0.10.0.jar!/deps.cljs
NPM dependency "react-dom" has installed version "^16.13.1"
"16.13.0" was required by jar:file:/C:/Users/pavel/.m2/repository/reagent/reagent/0.10.0/reagent-0.10.0.jar!/deps.cljs
shadow-cljs - HTTP server available at 
shadow-cljs - HTTP server available at 
shadow-cljs - server version: 2.10.21 running at 
shadow-cljs - nREPL server started on port 9000
shadow-cljs - watching build :client
[:client] Configuring build.
[:client] Compiling ...
[:client] Build completed. (934 files, 0 compiled, 0 warnings, 99.62s)
I get the same problem while testing both shadow-cljs watch client and npx shadow-cljs watch client .

Pavel Klavík20:08:14

Would it be possible to add an option to use EDN instead of Transit?

thheller20:08:24

I don't have a clue why this isn't working on your machine

thheller20:08:28

do you mess with java options in any way? like overriding the default encodings or something?

Pavel Klavík20:08:40

Probably somehow related to Windows-1250 encoding, maybe the problem got surfaced by switching from edn to transit

Pavel Klavík20:08:02

no, nothing like that

thheller20:08:17

where is that setting? I want to see what I have

Pavel Klavík20:08:45

what do you mean? what are java options?

thheller20:08:04

environment variables JAVA_OPTIONS or so

thheller20:08:00

hmm I have window-1252 in cursive as well

thheller20:08:30

what do you get in the CLJ REPL for (System/getProperty "file.encoding")?

Pavel Klavík20:08:56

I don't think there is anything in my JVM_OPTS or anything like that set up, I just installed JVM and didn't set anything up

Pavel Klavík20:08:21

Connecting to remote nREPL server...
Clojure 1.10.1
(System/getProperty "file.encoding")
=> "Cp1250"

thheller20:08:22

hmm yeah me neither. just guessing here ...

thheller20:08:32

hmm weird. that says UTF8 for me

thheller20:08:38

don't know why

thheller20:08:40

oh hehe. I do actually have JVM_OPTS=-Dfile.encoding=UTF8 as a global environment variable

thheller20:08:02

not sure if I set that at some point or if some installer added it?

thheller20:08:01

maybe that does something. try adding :jvm-opts ["-Dfile.encoding=UTF8"] to your shadow-cljs.edn?

thheller20:08:33

and probably wipe the .shadow-cljs/builds dir. no clue how the cache reacts to changing the file encoding 😛

Pavel Klavík20:08:22

ok, it works 🙂

thheller21:08:31

hmm now I have to figure out where this JVM_OPTS is coming from. I can't remember ever setting this.

Pavel Klavík21:08:43

Ya, good guessing 🙂.

thheller21:08:28

man that was a weird one

Pavel Klavík21:08:28

Thx a lot for figuring this out. @U0567Q30W the solution is to set file.encoding to UTF8 in JVM_OPTS, see the above

thheller21:08:23

especially since there is no file-writing involved in this 😛

cfleming22:08:13

Yeah, that’s a bit of a bad name - that’s actually the system encoding. Pavel and I tried setting that for IntelliJ (which IMO is probably a good idea) but it seems like it should be set for shadow too.

cfleming22:08:16

Which makes sense.

thheller22:08:28

ah. didn't know its the global encoding.

thheller09:08:20

maybe I could add a debug flag on the server side that dumps the messages it receives into a file or so

thheller09:08:36

this is where it fails so maybe you can try to redefine this function in the REPL

thheller09:08:23

so you could change (map transit-read) to

(map (fn [x] (try (transit-read x) (catch Exception e (log/warn-ex e ::ws-read-fail {:x x})))))

Pavel Klavík15:08:29

@U05224H0W How can I change this? From REPL?

thheller16:08:31

doubt that will show us anything we don't already have so don't bother

thheller09:08:36

maybe I'll do that as a default

thheller09:08:02

get at least some kind of clue whats wrong