Fork me on GitHub
#shadow-cljs
<
2020-01-08
>
Quest04:01:17

This might be more of a CLJS question so I can take it there if appropriate -- I'd like to access a property from some JavaScript namespaces in the CLJS layer. The JavaScript code to do this is supposed to be this:

import Constants from 'expo-constants';
const { version } = Constants.manifest;
On the CLJS side, I wrote my namespace declaration like this:
(:require ["expo-constants" :as expo-constants])
But when I try to access (.-Constants expo-constants), it just returns nil. I can run (type expo-constants) and it comes up as #object[Object] so it's something, but struggling to figure out how to access it further. Anyone have tips or troubleshooting ideas?

dangercoder06:01:35

Good morning, I'm having issues with deps.edn + shadow-cljs. I followed the official docs to figure out which alias to use for shadow-cljs :

:aliases {:shadow-cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.8.83"}
                          :main-opts ["-m" "shadow.cljs.devtools.cli"]}}}
When I try to execute the alias:
clj -A:shadow-cljs watch app
I get the following error: Error building classpath. Coordinate type not loaded for library :main-opts in coordinate ["-m" "shadow.cljs.devtools.cli"] Has anyone ran into similar issues?

dangercoder06:01:57

I'll look into it further after work.

thheller09:01:04

@quest see https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages. it likely is (:require ["expo-constants" :default expo-contants])

💯 4
Quest01:01:21

Dead on as usual, thanks @thheller. Properties such as (.-manifest expo-constants) became immediately accessible after using :default

thheller09:01:00

@jarvinenemil is your intent to use clj? you can just run with shadow-cljs watch app if you configure :deps {:aliases [:shadow-cljs]}

thheller09:01:49

but dunno about that error otherwise. comes from clj, not shadow-cljs. looks ok to me .. maybe ask in #tools-deps

thheller10:01:42

@jarvinenemil I see it now ... you :main-opts is listed as part of the :extra-deps map. its a misplaced }.

dangercoder12:01:31

The problem with rising up very early in the morning and trying to do things 😄. Thanks a lot @thheller

thheller12:01:50

might be worth reporting to #tools-deps regardless. the error message could probably be clearer. it just confused me at first.

dangercoder12:01:09

I think i had some other issues, when I was not using aliases No such var: ana/unwrap-quote im gonna continue this evening.

thheller12:01:23

might be a version conflict of some kind

👍 4
bbss13:01:27

I've upgraded a project to a newer version of shadow-cljs a while back and had some issues with the namespace wrt directory structure, at the time I solved it for shadow-cljs watch but now shadow-cljs release is giving me issues. I have two modules with :web-worker true, but I was getting this error:

[:main] Build failure:
Module Entry "shadow.cljs.devtools.client.worker" was moved out of module ":fetch-worker".
It was moved to ":shared" and used by #{:filter-worker :fetch-worker}.
I tried to move :web-worker into :worker-shared, and that builds, but I get "SHADOW_ENV is not defined" when it runs.

bbss13:01:35

My whole modules:

:modules    {:shared {:entries []}
                                  :web-shared {:entries []
                                               :depends-on #{:shared}}
                                  :worker-shared {:entries []
                                                  :depends-on #{:shared}
                                                  :web-worker true}
                                  :app {:entries [main.gsv.client]
                                        :depends-on #{:web-shared :shared}}

                                  :fetch-worker {:entries [main.gsv.fetch-worker]
                                                 :depends-on #{:worker-shared :shared}
                                                 }
                                  :filter-worker {:entries [main.gsv.filter-worker]
                                                  :depends-on #{:worker-shared :shared}
                                                  }}

bbss13:01:00

Using 2.8.83 now.

thheller13:01:04

@bbss oh I didn't consider 2 separate workers in the current setup. I enabled REPL/hot-reload inside workers. you can disable that for now by setting :devtools {:worker-inject false}

bbss13:01:22

Okay, trying. Thanks!

thheller13:01:47

or :worker-inject :worker-shared that might work too

bbss13:01:45

Hmm, having the same issue with both those options.

thheller13:01:16

are you setting it in the correct place?

thheller13:01:31

ie. in the build config but in :modules or so?

thheller13:01:33

hmm wait nevermind. you are not actually setting :web-worker true on the workers. I think your entire setup isn't actually supported right now

thheller13:01:03

you can set :devtools {:browser-inject web-shared} probably

thheller13:01:32

I need to think about shared worker code

thheller13:01:57

it might work fine if you don't set :web-worker true on the shared worker stuff

thheller13:01:01

only on the actual worker output

thheller13:01:12

yeah that should work

bbss13:01:48

I was setting web-worker true on the workers, but then I got the "was moved out of module" warnings.

bbss13:01:54

Trying that.

thheller13:01:57

right yeah only actual workers can have :web-worker true because they get some extra boilerplate

thheller13:01:48

but yeah you probably need to disable the worker-inject for now. didn't consider 2 workers for that

thheller13:01:23

so :devtools {:worker-inject false} and :web-worker true for both the workers but not the shared

dpsutton13:01:54

I'm giving an ignite presentation tonight to evangelize shadow-cljs and cljs. would love feedback in #off-topic from anyone with an opinion and 5 minutes to spare

thheller13:01:38

why #off-topic? totally on-topic in my view 🙂

dpsutton14:01:13

also didn't want to distract while yall were working through an actual issue 🙂

thheller13:01:09

OOO? whats that 😛

dpsutton13:01:14

wanted responses from general cljs and clojure people as well

dpsutton13:01:27

haha. gonna appeal to my c# friends

thheller14:01:17

mkdir app
npm init -y
npm i react create-react-class react-dom shadow-cljs

thheller14:01:40

npx create-cljs-project app will take care of creating generic boilerplate and some config

dpsutton14:01:25

oh never seen create-cljs-project. i mention create-cljs-app but it gets a bit heavy with the headless browser it brings along

thheller14:01:29

so its a bit better then npm init but less "full" then create-cljs-app

thheller14:01:07

its been in the readme for a while now https://github.com/thheller/shadow-cljs#quick-start

👍 4
thheller14:01:07

<a href=""> thats invalid, missing https://

bbss14:01:16

Getting

inspect_client.cljc:279 Uncaught ReferenceError: document is not defined
    at $fulcrologic$fulcro$inspect$inspect_client$install 
Removed the inspect preload and now getting
browser.cljs:430 Uncaught ReferenceError: window is not defined
    at browser.cljs:430

thheller14:01:51

minor "semantic" issue (.setAppElement Modal "#app") should not be run at the top level, as it will re-execute on every hot-reload. stuff like that goes into the init fn .. which you confusingly called main 😉

thheller14:01:21

probably not an issue in this case but in general that stuff goes into the init fn

👍 4
thheller14:01:41

@bbss then you also need to set :devtools {:browser-inject :web-shared :worker-inject false}

thheller14:01:26

I really need to figure out a way to make this config cleaner now that devtools in workers are supported. makes things slightly more complicated 😛

dpsutton14:01:36

thanks for the feedback so far. deployed those changes to the presentation and the site

bbss14:01:40

Workers load with that, but now I'm getting a bunch of warnings that are actually errors I expect:

shared.js:3199 failed to load goog.async.throttle.js TypeError: Cannot read property 'prototype' of undefined

env.evalLoad @ shared.js:3199
(anonymous) @ app.js:1482
shared.js:3199 failed to load goog.crypt.base64.js TypeError: Cannot read property 'SAFARI' of undefined
etc..

thheller14:01:10

that might be a bad closure-library version? if you use deps.edn/project.clj thats a "common" conflict nowadays ...

bbss14:01:34

alright, could be, investigating

thheller14:01:00

you should have these versions or newer, but not older

[com.google.javascript/closure-compiler-unshaded "v20191027"]

   [org.clojure/google-closure-library "0.0-20191016-6ae1f72f"]
   [org.clojure/google-closure-library-third-party "0.0-20191016-6ae1f72f"]

thheller14:01:21

shadow-cljs.edn ensures that but can't for the others

bbss15:01:15

Added that and still have the warnings that sound like errors, they happen for the started workers too. But the application is working again! had to remove a bunch of code that was not warning or erroring but referring a missing library in the project.clj dependencies (I think that was what's wrong?)

bbss15:01:49

Seeing if this works for release as well, thanks a lot once again @thheller!

thheller15:01:08

warnings that sound like errors?

bbss15:01:52

shared.js:3199 failed to load goog.async.throttle.js TypeError: Cannot read property 'prototype' of undefined
    at Object.goog.inherits (shared.js:1931)
    at eval (throttle.js:76)
    at eval (<anonymous>)
    at Object.goog.globalEval (shared.js:1817)
    at Object.env.evalLoad (shared.js:3197)
    at app.js:936
env.evalLoad @ shared.js:3199
(anonymous) @ app.js:936
shared.js:3199 failed to load fulcro.client.network.js TypeError: Cannot read property 'ErrorCode' of undefined
    at eval (network.cljc:24)
    at eval (<anonymous>)
    at Object.goog.globalEval (shared.js:1817)
    at Object.env.evalLoad (shared.js:3197)
    at app.js:960
env.evalLoad @ shared.js:3199
(anonymous) @ app.js:960
shared.js:3199 failed to load fulcro.client.primitives.js TypeError: goog.async.Throttle.base is not a function
etc..

bbss15:01:11

they're console.warning but sound like serious errors.

thheller15:01:13

those are definitely errors not warnings

thheller15:01:34

it just warns that they happened when trying to load those files

bbss15:01:28

Okay, but my code runs fine it looks like. :thinking_face:

thheller15:01:57

are there more errors? seems like a cascading error to me where one problem causes all the others

bbss15:01:57

There are more errors, but I think it's maybe in code I'm not using anymore. Making big cuts in the codebase after refactoring.

bbss16:01:47

when using release I'm getting

shared.js:2 Uncaught ReferenceError: $jscomp is not defined
    at shared.js:2
    at shared.js:1
Which I think is warned about with:
File: /Users/baruchberger/work/gsv/src/main/gsv/api/createIterable.js:89:8
--------------------------------------------------------------------------------
  86 |         if (prop === 'length') {
  87 |           return length;
  88 |         }
  89 |         if (prop === Symbol.iterator) {
--------------^-----------------------------------------------------------------
 variable $jscomp is undeclared
--------------------------------------------------------------------------------
  90 |           return iterator;
  91 |         }
  92 |         return source[prop];
  93 |       }
--------------------------------------------------------------------------------

bbss16:01:14

I think this has to do with polyfills of closure, but not sure how to fix it.

thheller16:01:31

@bbss you can set :compiler-options {:output-feature-set :es6}

thheller16:01:09

another option is adding :web-shared {... :prepend-js "window.$jscomp = {};"} .. there is an option issue about this I think. still need to dig into the closure compiler to figure out why this happens

Hukka16:01:46

I made a short demo with plain shadow-cljs today (no backend at all, no lein etc.). The repl always complained about unused vars, whenever I accessed any vars defined in the source. I don't remember seeing that before, and googling didn't show anything. Any ideas what's up with that?

bbss16:01:06

@thheller Thanks. Looks like the :output-feature-set :es6 + :prepend worked. Next issue is my js/window seems to be undefined. So many errors compared to earlier, did the closure compiler suddenly get a lot more strict or something?

thheller17:01:29

window is always undefined in workers?

bbss17:01:34

Yes, but in my main module.

thheller17:01:03

what has changed is the default of :compiler-options {:output-wrapper false}

thheller17:01:20

this used to default to false in multi-module builds but now also defaults to true there

thheller17:01:26

maybe thats causing your issues?

bbss18:01:25

Hmm, I'll need to read-up on that. But I think it's started since a clojurescript + shadow-cljs (and more strict closure) update a while back. Worked for non-advanced builds though, but now running into issues with advanced. I can make it work with shadow-cljs compile for now.