Fork me on GitHub
#shadow-cljs
<
2018-06-15
>
nickmbailey03:06:05

I’m having trouble using javascript libraries from a browser repl with shadow-cljs. The following fails in a browser repl but works in a node repl.

[2:1]~cljs.user=> (require '[moment :as m])
nil
[2:1]~cljs.user=> (m)
ReferenceError: module$node_modules$moment$moment is not defined

nickmbailey03:06:44

anyone know why the two would be different?

thheller06:06:02

@nickmbailey hmm it works for me?

$ shadow-cljs browser-repl
shadow-cljs - config: /mnt/c/Users/thheller/code/shadow-cljs/shadow-cljs.edn  cli version: 2.4.4  node: v9.4.0
shadow-cljs - connected to server
[:browser-repl] Configuring build.
[:browser-repl] Compiling ...
[:browser-repl] Build completed. (136 files, 35 compiled, 0 warnings, 6.93s)
[10:1]~cljs.user=> JS runtime connected.
[10:1]~cljs.user=> (require '["moment" :as m])
nil
[10:1]~cljs.user=> m
#object[g]
[10:1]~cljs.user=> (m)
#object[oa Fri Jun 15 2018 08:16:14 GMT+0200]

thheller06:06:36

@nickmbailey figured it out. there is a bug when you using a symbol instead of a string. (require '["moment" :as m]) works but (require '[moment :as m]) doesn't. https://github.com/thheller/shadow-cljs/issues/318 (fixed in 2.4.5)

wilkerlucio13:06:00

I was playing with it, and found a few things that might worth fixing:

wilkerlucio13:06:58

2. maybe its a mac problem, but see the outline on the header when I click, you can turn that off by css outline: none

thheller13:06:31

its the default react-table css but yeah that could be tweaked

thheller13:06:03

open an issue please for any bugs or suggestions

thheller13:06:41

this has been lingering for too long and should hopefully see more use now

wilkerlucio13:06:03

I just tried running it, but got an exception:

thheller13:06:35

Closure version conflict

wilkerlucio13:06:55

did cljs got updated or something?

thheller13:06:58

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

thheller13:06:24

CLJS just got a new release yes but I haven't updated to that yet

wilkerlucio13:06:47

oh, ok, I was going to update that, but I think that would break as well right? 😛

thheller13:06:57

no that should just work

thheller13:06:15

don't anticipate any breaking changes ... unlike Closure which seems to have a few with every release

wilkerlucio13:06:08

still getting that error =/ bumped CLJS and Closure, double checked the lein deps, only the newest closure is there

wilkerlucio13:06:11

[org.clojure/clojurescript "1.10.312"]
                 [com.google.javascript/closure-compiler-unshaded "v20180610"]

thheller13:06:37

and with CLJS 1.10.238?

wilkerlucio13:06:35

same thing, I can't compile with the newest shadow at all anymore

thheller13:06:50

lein clean?

thheller13:06:08

never know what that might fix

wilkerlucio13:06:51

tried, also deleted .shadow-cljs, but still getting the same problem

wilkerlucio13:06:15

I'm going to check again my deps, might be something there

wilkerlucio13:06:55

the deps seem right, not sure what else to look for

thheller13:06:35

hmm just tried in a test project and everything is working fine

wilkerlucio13:06:14

I was sure I had updated shadow, but seems not, and I was generating my deps list without shadow profile facepalm

wilkerlucio13:06:41

thanks for hanging with me on this, yeah, the issue was I forgot to update shadow in the project.clj

wilkerlucio13:06:54

but coming back to the report, I got this now:

wilkerlucio13:06:56

shadow-cljs - config: /Users/wilkerlucio/Development/nubank/shuffle/shadow-cljs.edn  cli version: 2.4.5  node: v8.11.2
shadow-cljs - running: lein with-profile +shadow run -m shadow.cljs.devtools.cli --npm run shadow.cljs.build-report app output.html
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See  for further details.
Failed reading cache for cljs.core: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: (FileInputStream); line: 1, column: 3964606])
 at [Source: (FileInputStream); line: 1, column: 3969231]
Failed reading cache for shuffle.chat.views.message: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: (FileInputStream); line: 1, column: 256687])
 at [Source: (FileInputStream); line: 1, column: 257415]
Failed reading cache for cljs.spec.gen.alpha: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: (FileInputStream); line: 1, column: 118722])
 at [Source: (FileInputStream); line: 1, column: 138937]
Failed reading cache for shuffle.chargeback.commons.purchases-widgets: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: (FileInputStream); line: 1, column: 180112])
 at [Source: (FileInputStream); line: 1, column: 184263]
Failed reading cache for cljs.stacktrace: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: (FileInputStream); line: 1, column: 74864])
 at [Source: (FileInputStream); line: 1, column: 126007]
Failed reading cache for shuffle.widgets.chargeback.ready.details: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: (FileInputStream); line: 1, column: 56211])
 at [Source: (FileInputStream); line: 1, column: 56715]
Failed reading cache for shuffle.chargeback.commons.chargebacks-widgets: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: (FileInputStream); line: 1, column: 42573])
 at [Source: (FileInputStream); line: 1, column: 45439]
Failed reading cache for fulcro.logging: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: (FileInputStream); line: 1, column: 41860])
 at [Source: (FileInputStream); line: 1, column: 43739]

wilkerlucio13:06:25

I was hoping it ends at some point, but seems like it's just hanging now

thheller13:06:40

probably just still compiling?

wilkerlucio13:06:58

my CPU is low, but I'm waiting more, its been a couple minutes already

thheller13:06:18

hmm shouldn't take that long

wilkerlucio13:06:38

this is a big app, does it usually takes much longer than release builds?

thheller13:06:59

no should be about the time of a release build (thats what it does in the background)

wilkerlucio13:06:25

ha, just finished 🙂

thheller13:06:26

the source map parser however might be really slow in bigger apps?

wilkerlucio13:06:50

and I can't see the time it took because of warnings and long output 😛

thheller13:06:14

warnings should be gone on second try though?

wilkerlucio13:06:11

thats fine, I can time it out later, one thing I found strange is that I got a lot of blank entries, and I think it's missing a lot of files from the project

wilkerlucio13:06:15

maybe it got the top ones

thheller13:06:50

hmm thats weird indeed

wilkerlucio13:06:10

I counted here, 676 blank lines

thheller13:06:04

very strange

nickmbailey15:06:07

@thheller awesome! thanks for the quick fix

levitanong15:06:59

@wilkerlucio @thheller that happens to me when i use https://date-fns.org/. Its structure is several smaller sub-folders that can each be separately required, so I assume when shadow tries to find out the library name, it doesn’t actually find anything.

thheller15:06:14

@levitanong thx, there indeed seems to be something funky in there. filenames however seem to work fine, its just missing the package name/version

levitanong15:06:05

Yeah, if i open it up the dropdown, it works fine.

richiardiandrea16:06:03

so @thheller I don't remember if I can or cannot at the moment have multiple entry points in the same namespace for :azure-app

colindresj16:06:55

@thheller any idea how one might use rebel readline with the shadow-cljs clojurescript repl?

thheller16:06:36

@richiardiandrea you can. currently no code splitting is performed

thheller16:06:47

@colindresj I didn't have time to look into that yet. might not be easy at the moment

colindresj17:06:11

Yeah I spent a little bit of time on it and it felt not straightforward. Wanted to check if I was missing something. Not a big deal

cjsauer21:06:57

Does shadow have a method for importing CSS files, similar to how JS does it? i.e. import "../node_modules/[NAME_OF_YOUR_LIBRARY]/lib/styles.css";

justinlee22:06:53

(it’s really webpack that does that. it isn’t a javascript thing)

cjsauer22:06:11

@lee.justin.m ah of course. I ended up writing a tiny little build hook that is working well enough

(defn copy-files
  {:shadow.build/stage :flush}
  [build-state & {:keys [dest files]}]
  (doseq [f files]
    (let [input (io/file f)
          input-name (.getName input)
          output (io/file dest input-name)]
      (io/make-parents dest input-name)
      (println (format "Copying %s to %s" input output))
      (io/copy input output)))
  build-state)

cjsauer22:06:32

This let's me copy the CSS into my public folder where I can then load it on the page

justinlee22:06:23

yea that works. i just use standard unix tools with npm scripts. imo you don’t need such tight integration with a monolithic build tool unless you’ve got a really big and complicated project. there’s something nice to just have simple scripts.

cjsauer22:06:19

For sure. I like the idea of someone being able to look at shadow-cljs.edn and seeing "ah, this is pulling some CSS files out of a node module".

cjsauer22:06:11

It let's the intent exist right next to the other project dependencies

justinlee22:06:59

yea i get the appeal for sure. i’m often of of two minds on the issue: some times the pendulum is on dead simple unix solutions and sometimes i like the One File To Rule Them All approach

cjsauer22:06:07

Yep, which is getting easier and easier thanks to projects like tools.deps and friends. I'm loving being able to pop off pretty sophisticated build solutions right inside Clojure. Really exciting direction.

cjsauer22:06:54

All of my repl and build scripts leverage simple unix scripts relying on clj. I'm liking it a lot.

cjsauer22:06:36

Makes splitting projects into smaller sub-projects really easy too.

justinlee22:06:10

you should write a blog post about your approach. i think a lot people would like to hear about that

cjsauer22:06:40

I definitely will soon. It's all scribbled into my notebook, just have to transfer it over.