Fork me on GitHub
#shadow-cljs
<
2019-02-21
>
neupsh01:02:28

Hello, I have a shadow-cljs project and I run npm alias (`shadow-cljs watch :main :renderer`) for my development workflow. I wanted to add a project.clj and move my dependencies to it (in :profile {:cljs... so I get a decent intellij + cursive support. I just moved the dependencies to the project file and added :lein {:profile "+cljs"} in my shadow-cljs.edn. Now i am getting the following exception:

neupsh01:02:57

Does anyone know what I could be doing wrong?

neupsh02:02:29

My project.clj looks like below:

neupsh02:02:32

(defproject example-app "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :license {:name "Eclipse Public License" :url ""}

  :dependencies [
                 [org.clojure/clojure "1.10.0"]
                 ;[org.clojure/clojure "1.9.0"]
                 [org.clojure/clojurescript "1.10.520"]
                 ;; Needed for shadowcljs if run using lein
                 [thheller/shadow-cljs "2.8.7"]
                 ]

  :profiles {:cljs
             {:dependencies [[reagent "0.8.1"]
                             [re-frame "0.10.6"]
                             [clj-commons/secretary "1.2.4"]
                             [cljs-ajax "0.8.0"]
                             [day8.re-frame/re-frame-10x "0.3.6-react16"]


                             [binaryage/devtools "0.9.10"]
                             ]

              ;:target-path "target/%s"
              :source-paths ["src"]}}
  )

neupsh03:02:40

I tried changing the shadow-cljs version in my project.clj (package.json still has the latest version: 2.8.7) down up to 2.7.7 where it still fails. Then if i use 2.7.6 it works fine

thheller07:02:04

@neupsh that is caused by a dependency conflict. check lein with-profiles +cljs deps :tree

thheller07:02:25

closure versions should be

[com.google.javascript/closure-compiler-unshaded "v20190121"]
   [org.clojure/google-closure-library "0.0-20190213-2033d5d9"]

👍 5
neupsh14:02:18

Thank you! It was the dependency conflict.

thheller07:02:52

it might work if you list shadow-cljs first

p-himik09:02:49

Invalid configuration
-- Spec failed --------------------

  {:output-dir ...,
   :compiler-options ...,
   :build-hooks ...,
   :modules ...,
   :module-hash-names ...,
   :devtools ...,
   :build-id ...,
   :asset-path "",
               ^^
   :target ...}

should satisfy

  non-empty-string?
By why? Why can't I just write /main.js in my index.html?

thheller09:02:40

use :asset-path "."

thheller09:02:07

the paths it emits is simply (str asset-path "/" filename)

p-himik09:02:24

Yeah. 🙂 But I mean, why this spec at all, why not just string??

thheller09:02:49

because you should be using a subdirectory

thheller09:02:11

the intention is that :output-dir is a directory dedicated to the output of shadow-cljs

thheller09:02:24

otherwise I make no guarantees that it won't overwrite your stuff

p-himik09:02:46

Subdirectory != server path. I can output to a separate directory and still use {:asset-path "."}.

thheller09:02:17

I can change the spec. It just doesn't fit into my mental modal to put everything at the "root"

thheller09:02:38

just use ".". otherwise I have to special case everything for empty ...

p-himik09:02:20

Yep, sure.

lsnape10:02:31

Morning, are there any known issues with the shadow's module loader on Chrome 72?

thheller10:02:31

depends on the version you are on. some problems were in between 2.8.0 - 2.8.6

lsnape10:02:42

Ah! Let me check

thheller10:02:51

not aware of any issues in older versions

lsnape10:02:23

I'll upgrade to latest. Worth a try

thheller10:02:25

no issues I'm aware of no.

thheller10:02:59

whats the problem?

lsnape10:02:22

We're getting undefined object console errors in module-loaded namespaces.

lsnape10:02:58

For objects that are explicitly required in at the top of the namespace, so they should be available!

lsnape10:02:23

Recompiling with latest...

thheller10:02:31

did you try shadow-cljs release your-app --pseudo-names to identify what is missing?

lsnape10:02:41

Not yet, but will do

lsnape10:02:42

Can reproduce with 2.8.7. And one of my colleagues says it works with release builds. More info incoming...

thheller11:02:12

I'm on chrome 73 beta but never had an issue with modules

lsnape11:02:58

Here is the compiled JS of the module-loaded namespace.

lsnape11:02:46

It's blowing up on line 13 trying to access sandi.main.view.content_STAR_

lsnape11:02:42

Curiously, if I access sandi.main.view just after the requires then it works!!

lsnape11:02:22

(sandi.main.view is a transitive require of the module-loaded namespace; it's not required anywhere else at the point when this file is loaded)

thheller11:02:20

hmm not sure I understand the last comment?

lsnape11:02:02

sandi.onboarding.view requires sandi.main.view. It's not required anywhere in the shared module.

thheller11:02:08

sandi.onboarding.view is one of your :entries in the modules?

lsnape11:02:25

yep:

:onboarding {:entries [sandi.onboarding.view]
                                       :depends-on #{:shared}}

thheller11:02:04

ok. you can open and open your build

thheller11:02:12

click compile or force-compile when the watch is running

thheller11:02:19

at the bottom it shows the module infos

thheller11:02:27

check if the file is in the correct module

thheller11:02:47

(don't see a reason why it wouldn't be but helps to verify)

lsnape11:02:11

Appears to be yes

lsnape11:02:19

That's pretty neat btw!

thheller11:02:47

well it will be neat once I actually come up with a proper design for all this UI stuff 😉

thheller11:02:52

are there any other errors during the load?

lsnape11:02:57

It's not that bad.

thheller11:02:01

something that would prevent the ns from loading correctly?

thheller11:02:25

eg. add a (prn :loaded) just after the content* definition?

👍 5
lsnape11:02:49

A few more errors, quite noisy so hard to see what's relevant.

lsnape11:02:05

That prn is shown after the errors are reported.

thheller11:02:36

so something doesn't work correctly during load I guess

lsnape11:02:36

and if I (def x sandi.main.view/content*) after the requires then I can see it loads with no errors.

lsnape11:02:14

So sandi.onboarding.view/content is being called before sandi.onboarding.view/content* is loaded.

lsnape11:02:12

And I can confirm the on-load function for that module is called before we try to resolve sandi.onboarding.view/content*.

thheller11:02:07

can't comment on that since I don't know what any of it does 😛

lsnape11:02:55

Sorry! The code checks that the on-load is called before trying to resolve view for that module.

thheller11:02:16

what is on-load?

lsnape11:02:45

(-> (loader/load (name module-id))
          (.then #(on-load! module)
                 #(on-error module)))

thheller11:02:59

and what does that do? what is module?

lsnape11:02:21

module is hash-map. It's used to initialise that module (set state in the app-db etc.). Crucially though, after on-load! is called a flag is set that allows the view in the module to be resolved.

lsnape11:02:35

This stuff has been working well and not been touched in quite a while. That's not to say there's not a latent bug in it!

thheller11:02:01

no idea. maybe I can guess something if you paste the errors you get on startup?

lsnape11:02:18

Uncaught TypeError: Cannot read property 'view' of undefined
    at sandi$onboarding$view$content (/dist/cljs-runtime/sandi.onboarding.view.js:16)
    at Object.G__95768__1 (cljs.core.js:3993)
    at Object.G__95768 [as call] (cljs.core.js:4166)
    at reagent.impl.component.js:130
    at Object.reagent$impl$component$wrap_render [as wrap_render] (reagent.impl.component.js:153)
    at Object.reagent$impl$component$do_render [as do_render] (reagent.impl.component.js:201)
    at day8.re_frame_10x.js:105
    at Object.reagent$ratom$in_context [as in_context] (reagent.ratom.js:61)
    at Object.reagent$ratom$deref_capture [as deref_capture] (reagent.ratom.js:70)
    at Object.reagent$ratom$run_in_reaction [as run_in_reaction] (reagent.ratom.js:1485)

thheller11:02:37

why is re-frame-10x in that trace?

lsnape11:02:01

Good question. It is used in the project, but I'm pretty sure removing it had no effect.

lsnape11:02:33

Well a workaround for now is to (def chrome-72-hack sandi.view.main/content*) at the top of each module view namespace, and I think I'm right in saying it'll be DCE in release (not that it matters all that much).

thheller11:02:14

why happens if you (js/console.log sandi.view.main/content*) instead and use it as normal?

lsnape12:02:28

Yes that works.

thheller12:02:53

logging it fixes the problem? or just the log works?

lsnape15:02:22

Logging under the require fixes the problem, just like def'ing .

joelsanchez12:02:51

it seems that when I compile my cljs for production this call: (.-token js-object) is munged and doesn't work anymore, is my only choice to use aget?

thheller12:02:34

(.-token ^js js-object)

joelsanchez12:02:23

I knew you'd reply if I mentioned I would use aget, your worst enemy

joelsanchez12:02:26

🙂 thank you

Whiskas13:02:18

Which chart lib do you guys like using with clojurescript?

Whiskas14:02:35

@joelsanchez cool, there is a guide to use it?

Whiskas14:02:40

i tried using react-chartjs directly

Whiskas14:02:43

but with no success

Whiskas14:02:55

the chart was’nt drawn

joelsanchez14:02:20

that wrapper served me well at the time, to draw realtime traffic stats

joelsanchez14:02:36

the code might be a bit bad but you can base yourself off it

joelsanchez14:02:53

chartjs is quite easy

Whiskas14:02:23

i’m having a problem with it not being renderized

Whiskas14:02:45

just wanted a react component to draw the graphs hah, i’m gonna try again