Fork me on GitHub
#shadow-cljs
<
2022-07-15
>
kenny20:07:18

Hi. I'm experimenting with react-table and am curious if there's a way to get exceptions thrown using non-minified library code. For example, when doing something wrong, I receive an exception like this:

index.production.js:22 Uncaught Error
    at s$jscomp$0 (index.production.js:22:1173)
    at eval (index.production.js:22:4096)
    at Array.map (<anonymous>)
    at t (index.production.js:22:4096)
    at W.e$jscomp$2.getAllColumns.a$jscomp$2.key (index.production.js:22:4096)
    at Object.eval [as getAllColumns] (index.production.js:22:477)
    at eval (index.production.js:22:2390)
    at Object.eval [as getHeaderGroups] (index.production.js:22:365)
    at Function.compute$ui$components$rtable$Table_STAR_ (rtable.cljs:28:27)
    at Function.eval [as cljs$core$IFn$_invoke$arity$3] (core.cljs:3935:15)
The stacktrace points to lines in the depths of a minified line in the file /node_modules/@tanstack/react-table/build/umd/index.production.js. The process of debugging is a game of guess and check since it's non-obvious what code is failing there. In that same /node_modules/@tanstack/react-table/build/umd directory, I see an index.development.js, and I'm wondering if I could tell shadow to switch to that in hopes the stacktrace becomes usable during development.

thheller20:07:08

so :js-options {:resolve {"@tanstack/react-table" {:target :npm :require "@tanstack/react-table/build/umd/index.development.js"}}}

winsome20:07:50

I'm trying to convert a project over to use shadow-cljs, but the compilation process blows up when it tries to load babashka.sci. In order to narrow down the problem, I've got it down to this repro:

npx shadow-cljs browser-repl
# wait for the repl to come up
(require '[sci.core :as sci])
ExceptionInfo Failed to process REPL command {:eof? false, :ns cljs.user, :form (require (quote [sci.core :as sci])), :source "(require '[sci.core :as sci])", :tag :shadow.cljs.repl/process-ex}
        shadow.cljs.repl/process-read-result (repl.clj:504)
        shadow.cljs.repl/process-read-result (repl.clj:478)
        shadow.cljs.repl/process-input (repl.clj:641)
        shadow.cljs.repl/process-input (repl.clj:619)
        shadow.cljs.devtools.server.worker.impl/eval82029/fn--82032 (impl.clj:698)
        clojure.lang.MultiFn.invoke (MultiFn.java:234)
        shadow.cljs.devtools.server.util/server-thread/fn--81669/fn--81670/fn--81678 (util.clj:269)
        shadow.cljs.devtools.server.util/server-thread/fn--81669/fn--81670 (util.clj:268)
        shadow.cljs.devtools.server.util/server-thread/fn--81669 (util.clj:241)
        java.lang.Thread.run (Thread.java:829)

thheller20:07:59

doesn't it tell you what that uncaught error was?

winsome20:07:23

There's a long stacktrace, which points to a null pointer while trying to compile sci.

winsome20:07:43

I'm not sure the best place to ask, here or sci, so I thought I'd start here with the repl command error

borkdude20:07:16

A repro would be most helpful, in the form of a repository that we can clone locally

borkdude20:07:38

This will automatically answer questions like: which version of SCI, etc, etc are you using

winsome20:07:12

:thumbsup: , I'm on the latest version of sci and shadow, but I'll try to put together a repro repo

borkdude20:07:10

you could also try wiping your .shadow-cljs and see if this helps. If that does help, then use the latest SCI commit on master

winsome20:07:19

I have done the .shadow-cljs wipe, that didn't fix it, but I can try with master SCI

thheller20:07:23

hmm does this problem go away if you (require 'cljs.analyzer.api) first before sci?

borkdude20:07:05

if wiping .shadow-cljs does not help, then it's probably not the problem we discussed recently

thheller20:07:57

well if sci never properly declares a dependency on the analyzer stuff there is no guarantee it'll be compiled "before" sci

winsome20:07:12

Alright, my minimal repro isn't reproing, so that's useful to know

thheller20:07:18

so it may still be compiling given that :parallel-build defaults to true and another thread might still be working on it

borkdude20:07:39

ok, could be

thheller20:07:11

although you are not compiling the self host version by default? the CLJ parts should all be loaded given that shadow-cljs uses them

thheller20:07:25

but dunno what copy-var does exactly

borkdude20:07:14

ah wait, an NPE in copy-var? yeah, that sounds familiar

winsome20:07:19

requiring cljs.analyzer.api before sci produces the same error as before

borkdude20:07:57

try bisecting on which copy-var call it fails

👍 1
borkdude20:07:09

and then post a SCI issue

winsome20:07:23

Oh wait, my code doesn't use copy-var at all, just create-ns new-var init parse-string eval-string* and eval-form. The NPE happens when trying to compile SCI. Also, it does compile just using the cljs compiler. Could you clarify what I should bisect through?

borkdude20:07:21

This doesn't ring a bell. Repro would still be good.

winsome21:08:00

I've picked up this problem again, and unfortunately I can't reproduce it in a basic shadow-cljs project with just the sci library. So, my question is: what sort of reasons would make this nondeterministic? Given my naive reproduction isn't reproducing it, but it stubbornly persists in the actual project.

borkdude21:08:29

I don't think it's non-deterministic necessarily, you should just keep working on a repro

borkdude21:08:01

e.g. take your existing project and remove things from it

borkdude21:08:19

until the error disappear and then start adding things back, this might give you some clues

winsome21:08:43

I've sliced and diced my project and it just tosses the NPE as soon as I add the sci.core require. I've removed every use of sci, and it's the require that causes the NPE.

winsome21:08:27

I'm not sure where to go from there - it's literally the same jar from my .m2 cache, same version of shadow-cljs, same version of clojure and clojurescript

borkdude21:08:38

which sci version is this?

borkdude21:08:57

can you try the latest SHA from SCI master?

borkdude21:08:56

if your project is public, I could take a look

borkdude21:08:45

if the code is private, you could add me temporarily as a contributor. else I wouldn't know how to help you further.

winsome21:08:58

It still tosses the NPE with SCI master.

winsome21:08:25

The repo is public, let me add some local work to the branch and push it so you can see.

winsome21:08:17

Alright, check out the feature/shadow-cljs branch if you can spare the time: https://github.com/dpetran/db

winsome21:08:09

The use of SCI is in fluree.db.dbfunctions.core.

borkdude21:08:35

@winsome what build should I start?

winsome21:08:02

I've been working with the :browser build, but they all exhibit the same problem.

borkdude21:08:37

so npx shadow-cljs build browser right?

borkdude21:08:59

s/build/compile

winsome21:08:19

yup! I've been using npx shadow-cljs server so I can mash recompile on demand

borkdude22:08:46

@winsome I'm getting:

[:browser] Compiling ...
The required JS dependency "process" is not available, it was required by "node_modules/js-sha3/src/sha3.js".

borkdude22:08:07

with npx shadow-cljs compile browser

thheller22:08:23

npm install shadow-cljs in the project is missing

winsome22:08:26

That's not the error I get when I run npx shadow-cljs compile browser.

winsome22:08:04

I have shadow npm installed as a devDependency. FWIW, I have seen that error before, but not currently. Maybe I need to clear my caches.

borkdude22:08:46

I did npm install before, but npm install shadow-cljs helped

thheller22:08:00

this has no shadow-cljs?

borkdude22:08:01

shadow-cljs wasn't in your package.json

winsome22:08:32

Are you looking at the feature/shadow-cljs branch? 506fdac

borkdude22:08:50

506fdac32041863dfc782fee0164bace49ac5399

borkdude22:08:10

anyway, now I could repro

👍 1
borkdude22:08:53

@winsome It seems to be something in 0.3.32 and/or with CLJS newest - it works with 0.3.31.

borkdude22:08:13

Although outside your project this works fine:

clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.11.60"} org.babashka/sci {:mvn/version "0.3.32" }}}' -M:dev -m cljs.main -re node
cljs.user=> (require '[sci.core])
nil

borkdude22:08:01

Inside your project the above works with 0.3.31 but not with 0.3.32. Not sure why, perhaps an interaction with shadow or so

borkdude22:08:39

Ah, if I remove the specific clojurescript version from your project, then 0.3.32 also works

winsome22:08:40

Thanks for investigating! I'll downgrade for now - does 0.3.32 have anything critical?

borkdude22:08:15

Perhaps it's something with shadow + a specific clojurescript version that pulls in some conflicting things. @U05224H0W might know

borkdude22:08:54

I can look into the specific NPE problem tomorrow, getting late here

winsome22:08:15

I think I'm happy to depend on shadow to do things unless I hear otherwise. Thank you for your time and problem solving!

thheller20:07:53

@winsome need the full stacktrace. otherwise can't tell you anything

kenny20:07:43

Ah that did it. Thank you Thomas!!

winsome21:08:00

I've picked up this problem again, and unfortunately I can't reproduce it in a basic shadow-cljs project with just the sci library. So, my question is: what sort of reasons would make this nondeterministic? Given my naive reproduction isn't reproducing it, but it stubbornly persists in the actual project.