Fork me on GitHub
#shadow-cljs
<
2022-05-18
>
timo10:05:33

Anyone knows a template to produce a fresh project with clj-tools and shadow-cljs?

timo10:05:12

I need a proper uber-build process for my project.

Samuel McHugh11:05:23

Hi, I'm trying to find the source of the following issue.

Failed to inspect file
  /home/foo/qux/node_modules/highlight.js/lib/languages/isbl.js

it was required from
  /home/foo/qux/node_modules/highlight.js/lib/index.js

Errors encountered while trying to parse file
  /home/foo/qux/node_modules/highlight.js/lib/languages/isbl.js
  {:line 1, :column 1, :message "The file could not be parsed as JavaScript."}
I have two projects A and B. A experiences the issue above. I have tried to trim away as much superfluous code as possible. B is created from scratch to match A as closely as possible. Notably • both projects have the exact same -Stree output. • Both have the exact same package.json and produced package-lock.json I have seen though that A produces one extra dir though. .shadow-cljs/builds/foo/dev/shadow-js . B does not have this directory. What could cause A to produce this?

2
Samuel McHugh11:05:38

Also the compile is non deterministic. Sometimes it fails, sometimes it doesn't. My suspicion is that the https://github.com/bhauman/devcards/issues/168 no longer works with 2.19.0

(ns frontend.highlight
  (:require ["highlight.js" :as hljs]))

(js/goog.exportSymbol "hljs" hljs)
(js/goog.exportSymbol "DevcardsSyntaxHighlighter" hljs)

;;;

{:ns-aliases {devcards-syntax-highlighter frontend.highlight}

thheller16:05:25

well what does /home/sam/Code/pitch-app/platform/node_modules/highlight.js/lib/languages/isbl.js look like?

thheller16:05:29

as to shadow-js missing. that is only created for :js-provider :shadow (eg. :target :browser) builds that use actual npm dependencies. other targets such as :npm-module or the :node-* variants won't produce this

thheller16:05:23

could just be a somehow corrupted js file?

danielstockton06:05:30

Getting something fairly similar when updating to 2.19.0

Failed to inspect file                                                                                  
  /home/dan/code/story-builder/node_modules/highlight.js/lib/languages/gml.js                                                                                                                                       
                                                                                                                                                                                                                    
it was required from                                                                                    
  /home/dan/code/story-builder/node_modules/highlight.js/lib/index.js                                                                                                                                               
                                                                                                          
Errors encountered while trying to parse file                                        
  /home/dan/code/story-builder/node_modules/highlight.js/lib/languages/gml.js                                                                                                                                       
  {:line 1, :column 1, :message "The file could not be parsed as JavaScript."}     @

danielstockton06:05:48

The gml.js doesn't look corrupted

thheller07:05:38

is that the full error? there should be more?

thheller07:05:54

I can't reproduce this locally

thheller07:05:28

what is your build :target? any specific :compiler-options? you sure you have the matching shadow-cljs, cljs, closure-compiler versions?

Samuel McHugh07:05:42

Try running your compile a few times just to be sure. Like I said it was non-deterministic for me.

Samuel McHugh07:05:50

:target :karma

thheller07:05:25

was that the full error for you? the error should be longer showing the actual cause?

thheller07:05:04

Closure compilation failed with 1 errors
--- node_modules/highlight_DOT_js/lib/languages/python.js:11
Cannot convert ECMASCRIPT_2018 feature "RegExp unicode property escape" to targeted output language.

thheller07:05:21

this error I can reproduce but just requires setting :output-feature-set :es8

thheller07:05:52

(which is the default for :karma so not needed to set it)

thheller07:05:32

ah there you have it

thheller07:05:40

that is a closure compiler error

thheller07:05:28

weird since that should be totally reproducible

thheller07:05:40

unless you have manually reduced the stack size or something?

Samuel McHugh07:05:08

If you're curious about the file. Only special thing I can see about it is it has some funky unicode chars

thheller07:05:01

that appears to match the source and error trace

thheller07:05:10

but supposedly was fixed a long time ago 😛

thheller07:05:32

There are two workarounds for this issue that I have found:

Break the string concatenation up into multiple statements
Increase JVM stack size, e.g. -Xss8M

thheller07:05:07

dunno why that would break randomly though. stack size is fixed by default IIRC

thheller07:05:45

why are you including this in the first place? do you really need syntax highlighting for isbl? whatever that is 😛

thheller07:05:01

so looks like this isn't the first time this has come up

Cal Herries07:05:04

The error is deterministic for me. It happens every time

thheller07:05:34

can you try setting :jvm-opts ["-Xss8M"] in shadow-cljs.edn (if you are not using deps.edn or project.clj, otherwise needs to be set there)

thheller07:05:16

just to see if that removes it?

Samuel McHugh07:05:22

yup, increasing the stack size looks like it fixes it.

1
Samuel McHugh07:05:56

so in conclusion the new closure compiler version can't handle large strings in the stack as well as the previous version?

thheller07:05:23

can't say. the error has come up before

thheller08:05:00

can't think of anything else to address this either

Samuel McHugh08:05:48

Feel free to add any extra info. Maybe someone will notice a regression introduced in the later version which blows up the stack in some edge cases.

Samuel McHugh08:05:51

Thanks for the help!

thheller10:05:30

which java versions do you use? how much RAM do you have? I can't reproduce this locally in any way but my guess is that java17 with 32gb of ram sort of influences this?

thheller10:05:04

I'd like to avoid a route where I bump the default stack size for every compile thread just because (like the closure compiler is doing)

thheller11:05:45

just to confirm: this is due to you using re-frame-10x right? or do you use highlight.js in any other context?

thheller11:05:20

the easiest fix for all of this is just not loading these highlight.js languages in the first place?

Samuel McHugh11:05:10

I'm on openJDK 11.0.15, 32GB of ram

Samuel McHugh11:05:48

I'm just working on a bit of an old app which uses devcards and devcards need to require highlight.js to work with shadow I suppose.

thheller11:05:34

:js-options {:package-overrides {"highlight.js" {"./lib/languages/isbl.js" false}}} would also work to just manually disable that one

👀 1
Samuel McHugh11:05:35

I agree this work isn't worth doing just for that, but if more people start reporting problems for other npm libraries, now we know

thheller11:05:24

haven't tested this so it might blow up

thheller11:05:31

but it'll make shadow-cljs just not bundle that file

thheller11:05:07

you could also fix it manually by overriding the cljsjs require and only including the languages you want

jpmonettas19:05:35

hi everybody! When working on a shadow-cljs browser-repl, Is there a way of reloading .clj files (for macros) when they change without restarting the repl?

thheller19:05:44

just work on them from the clojure repl? I typically work on macros from the clojure REPL only. often without even a CLJS build running

jpmonettas19:05:17

hmm not sure I follow, I'm tweaking some macros while trying them from cljs repl

jpmonettas19:05:04

so just running shadow-cljs browser-repl which starts just a cljs-repl

thheller19:05:04

for example a macro I just wrote

thheller19:05:51

shadow-cljs clj-repl (or my editor in this case)

thheller19:05:12

move cursor to one of the things in the comment form and eval that

thheller19:05:35

I mean sure if you macros get more complex that might become harder

thheller19:05:56

dunno what you are doing

thheller19:05:05

you can also just run shadow-cljs clj-repl while the browser repl is running

thheller19:05:09

they'll run in the same process

jpmonettas19:05:00

it is not easy for me to try them on the clj repl because the macro walks over cljs macroexpanded code, like (instrument (macroexpand (defmethod foo []...))), can't try them on clojure side since defmethod macroexpands to something different

jpmonettas19:05:50

ok, I guess if I'm running a shadow-cljs clj-repl I can do a (require '[ns] :reload)

jpmonettas19:05:29

yeah, it does the trick, thanks @thheller!