shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Karol Wójcik 2021-03-15T10:26:22.446100Z

How can I check which dependency includes cljs.test and cljs.pprint? I can see in shadow-report both of those included, whereas I don't have explicit require for them in the application.

thheller 2021-03-15T10:52:37.446600Z

currently there is no easy answer to this API wise

thheller 2021-03-15T10:53:01.447100Z

you can technically reconstruct it from the build data but no readymade function currently

Karol Wójcik 2021-03-15T11:01:18.447900Z

Hmm.. I think the fastest way would be to stub cljs.pprint with some ns which includes throw of an error and check stacktrace. Will check it out

jacekschae 2021-03-15T15:36:44.449200Z

If you wondering how to setup devcards with shadow-cljs here is an example: https://github.com/jacekschae/shadow-cljs-devcards also created a PR to add to the examples

👍 2
wombawomba 2021-03-15T22:01:23.451500Z

So I have some code that compiles fine in shadow-cljs, but gives me the following error when I try to load it in the browser:

SyntaxError: Invalid or unexpected token
   at eval (<anonymous>)
   at Object.goog.globalEval (<http://localhost:8281/static/js/base.js:577:21>)
   at Object.env.evalLoad (<http://localhost:8281/static/js/base.js:1670:12>)
   at <http://localhost:8281/static/js/base.js:1946:12>
The error doesn't really tell me where the problem lies, and the compiled js file being loaded is >4000 lines. How can I figure out what's causing the error?

wombawomba 2021-03-15T22:02:25.451800Z

Like, is there a way to eval the statements in the file one by one?

thheller 2021-03-15T22:02:49.452300Z

the only way I have seen this error before is when two shadow-cljs instances are running at the same time and writing to the same files

thheller 2021-03-15T22:02:52.452500Z

messing each other up

thheller 2021-03-15T22:03:35.452900Z

could also be one instance but two builds using the same :output-dir

wombawomba 2021-03-15T22:03:43.453300Z

I did do that yesterday

thheller 2021-03-15T22:03:57.454Z

you can set :devtools {:loader-mode :script} in the build config

wombawomba 2021-03-15T22:05:01.455Z

how do I clean this up? should deleting the output directory suffice?

thheller 2021-03-15T22:05:22.455300Z

first identify that there is only one instance running

wombawomba 2021-03-15T22:05:52.456Z

yeah there are zero instances right now :)

thheller 2021-03-15T22:06:36.456800Z

and you only have one build writing to the output-dir? and no other processes modifying that output in any way?

wombawomba 2021-03-15T22:06:44.457Z

yeah

wombawomba 2021-03-15T22:06:54.457400Z

but like I said, I had two earlier

thheller 2021-03-15T22:07:28.458300Z

restarting will recreate all the files properly but if you want you can clean out the output-dir as well

wombawomba 2021-03-15T22:07:39.458700Z

alright

thheller 2021-03-15T22:07:44.459Z

unlikely to change anything

wombawomba 2021-03-15T22:07:54.459600Z

I did restart a few times afterwards, so maybe something else is going on here

thheller 2021-03-15T22:08:00.459800Z

the :loader-mode will load things as one script at a time, instead of all at once

thheller 2021-03-15T22:08:26.460400Z

but normally the eval loader should also tell you which file failed at least

wombawomba 2021-03-15T22:08:45.460800Z

yeah it does tell me, but it's not helpful because that file is huge

wombawomba 2021-03-15T22:09:16.461Z

yeah no, still fails

wombawomba 2021-03-15T22:09:23.461300Z

I'll try the loader-mode thing next

thheller 2021-03-15T22:09:50.461700Z

which server is serving :8281?

wombawomba 2021-03-15T22:10:00.461900Z

shadow-cljs

wombawomba 2021-03-15T22:12:45.463200Z

alright, :loader-mode :script gave me a much nicer error, albeit in a different file...

wombawomba 2021-03-15T22:13:13.463900Z

I'll try to solve that one and see if I can get to the other thing that was failing 🙂

thheller 2021-03-15T22:13:28.464300Z

:script will not abort loading if one file fails. so it likely just creates a cascade of other errors

wombawomba 2021-03-15T22:13:43.464500Z

oh wait, duh

wombawomba 2021-03-15T22:13:56.464900Z

yeah, the original error is there — I just missed it

wombawomba 2021-03-15T22:14:13.465200Z

it's telling me which line is failing now though

wombawomba 2021-03-15T22:14:29.465400Z

it's a bad regex

wombawomba 2021-03-15T22:14:37.465700Z

thanks for the help!

thheller 2021-03-15T22:14:47.465900Z

interesting. good to know.

wombawomba 2021-03-15T22:25:41.466900Z

BTW, is there a way to get something like lein checkouts with shadow-cljs?

wombawomba 2021-03-15T22:26:49.468200Z

right now my workflow when working on cljs/cljc libraries with my cljs project is basically 1. make a change to a library 2. quit shadow-cljs 3. reinstall the library to my local maven repo 4. start shadow-cljs again 5. find something I want to change, go back to 1

wombawomba 2021-03-15T22:27:48.468600Z

...which seems pretty far from optimal 🙂

thheller 2021-03-15T22:31:11.468900Z

well the obvious answer is use lein checkouts 😉 or deps.edn via :local/root

thheller 2021-03-15T22:32:10.469500Z

or just adding the :source-paths might work too (thats what I usually do)

wombawomba 2021-03-15T22:38:29.470400Z

huh 🙂 I didn't realize I could use lein and shadow-cljs together

wombawomba 2021-03-15T22:39:03.470600Z

very cool