Fork me on GitHub
#shadow-cljs
<
2021-02-11
>
Roman Liutikov09:02:02

Is it expected that shadow won't infer an extern and won't produce a warning? I'm seeing a renamed JS property slipped into release build

thheller10:02:13

@roman01la you need to be a bit more specific. it entirely depends on the code whether externs are generated or not.

Roman Liutikov10:02:44

I see, here's more context code

(defn get-x []
  ^js/LibraryX @lib-x)

(let [x (get-x)]
  (.methodA x)
  (.methodB x))
manual externs
LibraryX.prototype.methodA = function() {}

Roman Liutikov10:02:04

for the above setup methodB gets renamed in release build and there's no compiler warning emitted

thheller10:02:21

(defn get-x ^js []
  @lib-x)

Roman Liutikov10:02:24

now when I remove manual externs and hint those values with ^js inference seems to work fine in release

thheller10:02:05

but you should be getting warnings in this case. or automatic externs inference

Roman Liutikov10:02:28

unfortunately I didn't get any

zendevil.eth10:02:36

I’m running a watch like so:

shadow-cljs watch app
But in the browser app, I’m getting two errors:
Connection closed
and
Stale client
How to fix this error? There are warnings but no errors in the shadow command line

Roman Liutikov10:02:57

why does ^js work but more specific ^js/Lib doesn't?

zendevil.eth10:02:42

Now I’m only getting Connection closed

thheller10:02:55

@roman01la both are the same as far as shadow-cljs is concerned. I'm just not sure that the typehint directly on the defer properly propagates to the function return value.

thheller10:02:36

@ps that means the JS that is being loaded was not produced by the watch you started. that can either happen if you have 2 shadow-cljs isntances running in the same project. or you changed the paths somewhere but still access the "old" JS

zendevil.eth10:02:56

how to close all shadow-cljs instances?

zendevil.eth10:02:05

i might have been running two

zendevil.eth10:02:29

I’ve tried shadow-cljs stop

Roman Liutikov10:02:36

> both are the same as far as shadow-cljs is concerned. I'm just not sure that the typehint directly on the defer properly propagates to the function return value. interesting, so there two things going on 1. shadow doesn't emit a warning 2. switching to ^js solves the problem, externs inferred correctly

thheller10:02:30

@ps stop will only stop the latest one. if you somehow started another you need to kill it manually. you can use the java tools to find the process. just jps or jcmd

Roman Liutikov11:02:57

@thheller I can verify that adding return type hint solves the above problem, however it doesn't exist in plain cljs

thheller12:02:14

what does? shadow-cljs doesn't do anything special in that regard?

Roman Liutikov12:02:53

I mean that in plain cljs property renaming doesn't happen, but in shadow it does happen, even though shadow doesn't emit infer warning

thheller12:02:42

you need to be more precise. I do not have enough information to know what you are referring to. for example the renaming may not happen in regular CLJS because you have some CLJSJS externs that happen to handle it, they are often over-generated so it might even be from a different package or so.

thheller12:02:23

I'm happy to take a look at reproducible sample code any time (and fix it if there are actual issues)

Roman Liutikov12:02:06

good point about third party externs, I'll put a minimal repro once I manage to reduce the scope of the problem

thheller12:02:19

in general shadow-cljs does more externs inference, not less so I'd be very surprised if thats the cause

Roman Liutikov12:02:37

yeah that's why it seemed weird to me

Roman Liutikov12:02:50

another interesting case I just hit is that during dev shadow emits an inferring warning, but release build doesn't emit the warning and generated JS looks correct

Roman Liutikov12:02:34

this is not a problem, since adding a hint to silence the compiler in dev is fine, but still interesting inconsistency

thheller12:02:33

can't say anything without reproducible examples

👍 4
zendevil.eth14:02:37

I’m trying to run the shadow repl on cursive

zendevil.eth14:02:54

this is my repl configuration

zendevil.eth14:02:14

But I’m getting this error:

EOF while trying to sync input stream.

zendevil.eth14:02:21

when clicking run

thheller14:02:31

can you see the warning on the bottom? pretty sure you need to add "localhost" to the Host field

thheller14:02:33

and also select nREPL above, then also select "use port from nrepl file"

zendevil.eth14:02:36

@thheller it’s stuck on: Connecting to remote nREPL server...

thheller14:02:05

is shadow-cljs running? did you actually configure that port? is it actually running on localhost?

thheller14:02:56

please use the above setting. you really should not be hardcoding the port ever.

zendevil.eth14:02:16

this is the beginning of the shadow output:

shadow-cljs - HTTP server available at 
shadow-cljs - server version: 2.8.93 running at 
shadow-cljs - nREPL server started on port 7002
shadow-cljs - watching build

thheller14:02:54

seems fine then. maybe your firewall is blocking the port?

zendevil.eth14:02:10

how to fix that?

thheller14:02:37

sorry I cannot help you with macOS questions and note the "maybe". I don't have a clue if that is the cause

zendevil.eth14:02:50

also I still see shadow-cljs connection closed

zendevil.eth14:02:11

This is the output from jcmd

zendevil.eth14:02:14

51168 clojure.main -i /private/var/folders/96/df02xppj77g7dx698gtmwmrw0000gn/T/form-init5834689007742471668.clj
53409 clojure.main -i /private/var/folders/96/df02xppj77g7dx698gtmwmrw0000gn/T/form-init6184901872508431686.clj
52882 clojure.main -m leiningen.core.main run -m shadow.cljs.devtools.cli --npm watch app
52885 clojure.main -i /private/var/folders/96/df02xppj77g7dx698gtmwmrw0000gn/T/form-init2867749071698962093.clj
51910 
53993 sun.tools.jcmd.JCmd

thheller14:02:51

ok that is one shadow-cljs process. the others are lein processes. not sure if you mean to have those.

zendevil.eth14:02:12

i mean to have one lein process that’s running my app’s server

thheller14:02:03

ok. but you did not start shadow-cljs in those processes? meaning there is no lein-shadow in your project.clj?

zendevil.eth14:02:29

I’m not sure:

zendevil.eth14:02:29

(defproject vendo "0.1.0"

  :description "Main Page. Vendomarch."
  :url ""

  :dependencies [[ch.qos.logback/logback-classic "1.2.3"]
                 [cheshire "5.10.0"]
                 [cljs-ajax "0.8.0"]
                 [clojure.java-time "0.3.2"]
                 [com.cognitect/transit-clj "1.0.324"]
                 [com.fasterxml.jackson.core/jackson-core "2.11.0"]
                 [com.fasterxml.jackson.core/jackson-databind "2.11.0"]
                 [com.google.javascript/closure-compiler-unshaded "v20200504" :scope "provided"]
                 [cprop "0.1.17"]
                 [day8.re-frame/http-fx "0.1.6"]
                 [expound "0.8.4"]
                 [funcool/struct "1.4.0"]
                 [luminus-aleph "0.1.6"]
                 [luminus-transit "0.1.2"]
                 [luminus/ring-ttl-session "0.3.3"]
                 [markdown-clj "1.10.4"]
                 [metosin/jsonista "0.2.6"]
                 [metosin/muuntaja "0.6.7"]
                 [metosin/reitit "0.5.2"]
                 [metosin/ring-http-response "0.9.1"]
                 [mount "0.1.16"]
                 [nrepl "0.7.0"]
                 [org.clojure/clojure "1.10.1"]
                 [org.clojure/clojurescript "1.10.764" :scope "provided"]
                 [org.clojure/core.async "1.1.582"]
                 [org.clojure/google-closure-library "0.0-20191016-6ae1f72f" :scope "provided"]
                 [org.clojure/google-closure-library-third-party "0.0-20191016-6ae1f72f" :scope "provided"]
                 [org.clojure/tools.cli "1.0.194"]
                 [org.clojure/tools.logging "1.1.0"]
                 [org.webjars.npm/bulma "0.8.2"]
                 [org.webjars.npm/material-icons "0.3.1"]
                 [org.webjars/webjars-locator "0.40"]
                 [re-frame "0.12.0"]
                 [reagent "1.0.0-alpha2"]
                 [ring-webjars "0.2.0"]
                 [ring/ring-core "1.8.1"]
                 [ring/ring-defaults "0.3.2"]
                 [selmer "1.12.27"]
                 [thheller/shadow-cljs "2.8.93" :scope "provided"]

                 ;; non-default dependencies
                 [com.novemberain/monger "3.1.0"]
                 [clj-http "3.10.1"]
                 [org.mongodb/mongo-java-driver "3.12.1"]
                 [com.cemerick/url "0.1.1"]
                 [com.draines/postal "2.0.3"]
                 [digest "1.4.9"]


                 ;; cljs
                 [rgm/tailwind-cljs "0.1.0"]
                 [cljs-bean "1.5.0"]

                 [clojurewerkz/elephant "1.0.0-beta18"]
                 ]

  :min-lein-version "2.0.0"
  
  :source-paths ["src/clj" "src/cljs" "src/cljc"]
  :test-paths ["test/clj" "test/cljs"]
  :resource-paths ["resources" "target/cljsbuild"]
  :target-path "target/%s/"
  :main ^:skip-aot vendo.core

  :plugins [[lein-shadow "0.2.0"]] 
  :clean-targets ^{:protect false}
  [:target-path "target/cljsbuild"]
  :shadow-cljs
  {:nrepl {:port 7002}
   :builds
   {:app
    {:target :browser
     :output-dir "target/cljsbuild/public/js"
     :asset-path "/js"
     :modules {:app {:entries []}}
     :devtools
     {:watch-dir "resources/public" :preloads [re-frisk.preload]}
     :dev
     {:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}}}
    :test
    {:target :browser-test;;:node-test
     :test-dir  "resources/public/js/test"
     :autorun true
     :ns-regexp ".*"

     :devtools  {:http-port          8021
                 :http-root          "resources/public/js/test"}

     }
    :node-test
    {
     :target :node-test
     :output-to "target/test/test.js"
     }

    :ci
    {
     :target :karma
     :output-to "target/ci.js"
     :ns-regexp ".*"
     }
    
    }}

  :npm-deps [[shadow-cljs "2.8.93"]
             [create-react-class "15.6.3"]
             [react "16.13.0"]
             [react-dom "16.13.0"]]
  :npm-dev-deps [[xmlhttprequest "1.8.0"]]

  :profiles
  {:uberjar {:omit-source true
             :prep-tasks ["compile" ["shadow" "release" "app"]]
             :aot :all
             :uberjar-name "vendo.jar"
             :source-paths ["env/prod/clj"  "env/prod/cljs" ]
             :resource-paths ["env/prod/resources"]}

   :dev           [:project/dev :profiles/dev]
   :test          [:project/dev :project/test :profiles/test]

   :project/dev  {:jvm-opts ["-Dconf=dev-config.edn" ]
                  :dependencies [[binaryage/devtools "1.0.0"]
                                 [cider/piggieback "0.5.0"]
                                 [pjstadig/humane-test-output "0.10.0"]
                                 [prone "2020-01-17"]
                                 [re-frisk "1.3.2"]
                                 [ring/ring-devel "1.8.1"]
                                 [ring/ring-mock "0.4.0"]]
                  :plugins      [[com.jakemccrary/lein-test-refresh "0.24.1"]
                                 [jonase/eastwood "0.3.5"]] 
                  :source-paths ["env/dev/clj"  "env/dev/cljs" "test/cljs" ]
                  :resource-paths ["env/dev/resources"]
                  :repl-options {:init-ns user
                                 :timeout 120000}
                  :injections [(require 'pjstadig.humane-test-output)
                               (pjstadig.humane-test-output/activate!)]}
   :project/test {:jvm-opts ["-Dconf=test-config.edn" ]
                  :resource-paths ["env/test/resources"] 
                  }
   :profiles/dev {}
   :profiles/test {}})

thheller14:02:59

ok, sorry cannot help you with lein-shadow related issues

zendevil.eth14:02:37

what if I remove the lein-shadow plugin?

thheller14:02:48

yes, you should do that

thheller14:02:06

basically what you want is EITHER running everything directly via lein OR running the server parts with lein and the CLJS parts with shadow-cljs

thheller14:02:24

NOT both. it appears to me that you currently try to do both and them interfering with each other

thheller14:02:52

I do recommend running things separately always

thheller14:02:30

so in one process you run lein repl or whatever the command there is and in another process you run shadow-cljs watch app

thheller14:02:54

(I have also never used luminus so I'm not sure how all that works)