This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-13
Channels
- # announcements (15)
- # babashka (48)
- # beginners (5)
- # biff (4)
- # calva (3)
- # cider (10)
- # clerk (16)
- # clj-kondo (6)
- # cljdoc (20)
- # cljs-dev (13)
- # clojure (117)
- # clojure-argentina (1)
- # clojure-brasil (5)
- # clojure-europe (40)
- # clojure-nl (1)
- # clojure-norway (111)
- # clojure-uk (5)
- # clojurescript (16)
- # cursive (20)
- # datascript (2)
- # datomic (106)
- # etaoin (2)
- # events (3)
- # funcool (1)
- # graphql (1)
- # helix (8)
- # hyperfiddle (36)
- # leiningen (12)
- # matrix (1)
- # nrepl (1)
- # off-topic (61)
- # other-languages (10)
- # polylith (22)
- # practicalli (1)
- # reagent (28)
- # reitit (11)
- # remote-jobs (3)
- # ring (12)
- # shadow-cljs (109)
- # slack-help (6)
- # solo-full-stack (23)
- # squint (7)
- # xtdb (11)
Has anyone successfully used philoskim/debux-stubs
with shadow-cljs
? I'm using debux
for debugging but ran into an issue where I forgot to remove a #d/clog
tag from a commit, breaking the application.
I've seen an https://github.com/day8/re-frame-debux/issues/30#issue-607861849 where @thheller suggests using ns aliases (`{:ns-aliases {debux.cs.core debux.cs.stubs}}` in my case, I guess) in the build options. However, it seems this approach doesn't work for tags. I assume this is because the tag is explicitly defined as {d/clog debux.cs.core/clog-tag}
, making it impossible to substitute the namespace?
Does anyone have a solution for safely using debux tags in shadow-cljs
, or is manual removal before making a commit the only way to go?
I'm currently attempting to reimplement data_readers.cljc
for the project, but maybe there is a more graceful way to handle the issue?
I'm still (unfortunately) on this path of using webpack as an external bundler with a wasm library (automerge 2) ... and I've had it working at various points, but after a library upgrade and some changes, I see some errors I don't understand when loading the page. I'll put them in reply so as not to pollute the channel ...
Any idea what I might be doing wrong (presumably with webpack) that would cause this error?
I do - but maybe something changed and my webpack config has to be different - I'll work on it some more and see if I can resolve the error through the webpack config.
@thheller I'm still on this path of trying to use a wasm
library.
I previously had it working, and the wasm library would show up in my cljs code as a promise, and you helped me use js-await
to access the contents of that promise, and then I was able to use that module from there.
They've made an update to the library, and now it doesn't appear as a promise anymore, but when I try to do things with it, it complains that .use
hasn't been called on the module, which sounds like maybe it's not being loaded correctly.
I know this isn't exactly supported territory for shadow-cljs, but do you have any ideas for things I might try?
I'm currently using an import like this:
["@automerge/automerge" :rename {next automerge}]
this means absolutely nothing to me. can you provide more context? JS examples/docs?
Yes, I'm sorry - the project I'm trying to use is:
https://github.com/automerge/automerge/
I'm using webpack as an external js-provider
with shadow-cljs.
A javascript example of using it with webpack is provided here, about half a page down:
https://automerge.org/docs/quickstart/
Essentially, I'm just trying to call .init
on automerge, as they show there. And this has worked previously with this wasm setup, but at some point they upgraded their library in such a way that it no longer works, and notably, as I mentioned, it doesn't show up as a promise anymore in cljs.
I see const Automerge = require('@automerge/automerge')
and then let doc1 = Automerge.init()
next
is the API they're migrating to, so certain things are essentially only possible in next
, so despite it not being mentioned in the quickstart, it is supported and in fact recommended in their library.
translated to cljs that is (:require ["@automerge/automerge" :as Automerge])
and then (def doc (Automerge/init))
Here - I think for the purposes of this discussion, I can probably reproduce the same error without next. One minute, and I can verify.
And speaking with the developers of automerge, they said that users should never have to call use
themselves, and that it normally happens as a result of loading the module.
Yes, I mean, in so far as: • this configuration worked with a previous version of the library • webpack runs and emits js that I can load in the browser • it's the same webpack config present in the quickstart I linked above
Which part of what you see above is related to the js bundler? Just webpack doing the packaging?
Anyway, it sounds like you think this isn't anything related whatsoever to shadow-cljs.
I would put this in a JS file
import * as Automerge from "@automerge/automerge"
let doc = Automerge.init()
console.log(doc)
if that works we can look further and figure out what adding shadow-cljs into the mix does
@thheller Ok, so I did what you asked, and it works for both the "normal" library and the "next" submodule. The output looks like this in the console (not very useful, but just to prove I did it):
and what does it look like if you translate that JS code to CLJS. only that. nothing else?
Do you mean that I should try to create the most minimal cljs project that does just this? I can certainly try that and report back.
Ok, I will try to do exactly that - but it will probably take me a bit. I'll report back to you once I have it set up.
@thheller Ok, I have it, with the same results as in my larger project (ie, I get the error which doesn't occur in plain js). How can I send you a .tgz of the project ?
<mailto:[email protected]|[email protected]> or just slack
Here you go. I put some minor comments in the readme, but you just have to npm install
and then you can execute the shell script run
and then you can load index.html in the browser.
ok, I'm guessing this is some sort of issue in webpack and its ESM/WASM bundling when used from a commonjs require
file
but .wasm
imports in the browser are non-standard and therefore each bundler does something slightly different
webpack in this case rewrites it to use the regular wasm initialization steps, which are async
and it therefore uses its alternative loading mechanism that turns EVERY import async
I changed the build config to
{:dev-http {8000 "resources/web"}
:builds {:app {:target :browser
:output-dir "resources/web/js"
:modules {:main {:init-fn minimal.core/init}}
:js-options {:js-provider :external
:external-index "target/index.js"
:external-index-format :esm}}}}
but I think it can run into issues with the async loading, as in trying to use the dependencies before they finish loading
since the webpack async loading mechanism is hidden from the user, there is no way to reliably detect it
@thheller Thank you so much for looking into this - I've been in meetings all afternoon so I haven't had a chance to give this a try, but I really appreciate your thorough investigation and I'm hopeful that this can get things working for me again (although I understand what you said about async loading) ... I'm curious if it will change how the module "appears" to me (since, as I said, in the previous versions, the actual module showed up as a promise) ...
It does appear to work! That's great. But what you said about async loading and not being able to reliably wait for it is disturbing, but I understand we can't do much about it. I'll give the feedback back to the automerge guys. Thank you again for your efforts on this - I didn't even know about the :external-index-format
option.
@thheller So as I said, that option seems to fix that fundamental issue, but what I see now is that if I load my application in a new browser window, I get the following error (followed of course by others):
And yeah, it's not even consistent - sometimes it takes more than 1 reload for the problem to go away, so it may just be pure luck whether or not it happens.
the problem is that webpack thinks it is in control of everything and only ensures its own code is loaded properly and in order
Ok, thanks very much - this approach is dead in the water then. I'll go talk to the automerge devs and see if I can come up with something else !
would be good if automerge had a way where you can initialize the wasm stuff yourself. i.e. not use import
with a .wasm
file
as no browser supports that and is as of now a bundler feature, which shadow-cljs doesn't yet have
Yeah, I just asked them if there was a way to load the wasm myself (by coincidence) because it seems like that would let me bypass all of this and just use shadow-cljs like a normal person instead of in this webpack way anyway ...
it'd be so simple if their Automerge.init
just took an argument that is the wasm stuff
import * as Automerge from "@automerge/automerge"
import { wasm } from "@automerge/automerge-wasm"
let doc = Automerge.init(wasm)
console.log(doc)
Yes - that would be very nice indeed. Although in their typescript declarations they directly import some stuff from the wasm project (like import type { ... } from "@automerge/automerge-wasm"
) so I'm not sure if that's even possible for them. But I'll ask ...
Ok, I sent you something through the github sponsorship program - I'd rather have my company do something, but at least this shows that I appreciate the help you have given me over the past few years. Thank you again.
Hey @U07VBK5CJ, I’m curious if you made progress here!
@U017QJZ9M7W was it auto merge specifically you were interested in ?
Yea that’s right
So for the time being I am stuck, because using web pack as a bundler in this way seems to introduce a loading race condition with the initialization of auto merge. However, I am talking to the auto merge guys, and they are going to eventually provide an interface that will let me load the wasm module myself, and then initialize auto merge with it, meaning that I won’t have to use the web pack bundler anymore at all. The timeline isn’t clear yet, but I am waiting on them to give me an example of how to do this.
Nice who are you talking to? Are you in their discord?