This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-22
Channels
- # announcements (18)
- # babashka (9)
- # beginners (22)
- # biff (2)
- # calva (17)
- # clj-kondo (5)
- # clojure (9)
- # clojure-europe (25)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-uk (7)
- # clojuredesign-podcast (6)
- # clojurescript (61)
- # cursive (11)
- # data-science (1)
- # datahike (3)
- # datomic (2)
- # humbleui (2)
- # hyperfiddle (7)
- # jobs (1)
- # jobs-discuss (4)
- # joyride (1)
- # overtone (7)
- # re-frame (2)
- # reitit (9)
- # releases (2)
- # remote-jobs (8)
- # scittle (1)
- # shadow-cljs (48)
- # squint (8)
I'm still trying to see if there's a way to get the newest automerge
working in the context of a cljs application built by shadow-cljs
. I'm hoping that I can load the wasm myself, and avoid any kind of weird external bundling, because I was running into race conditions having to do with using webpack as an external bundler. I'm sort of trying to start from scratch a little bit, and depending on @automerge/[email protected]
, when I try to do a shadow-cljs build, I see the following:
[:app-simple] Configuring build.
[:app-simple] Compiling ...
[:app-simple] Build failure:
Failed to inspect file
/Users/me/project-wasm/node_modules/@automerge/automerge-wasm/bundler/automerge_wasm_bg.wasm
Errors encountered while trying to parse file
/Users/me/project-wasm/node_modules/@automerge/automerge-wasm/bundler/automerge_wasm_bg.wasm
{:line 1, :column 0, :message "Character '' (U+0000) is not a valid identifier start char"}
Does that kind of error message give you any clue about what might be happening ? I don't know if this could be because of how this library is being referenced in my imports ?didnt we go over this before? shadow-cljs does not support bundling .wasm files. so it any sources do import ... from "./some.wasm"
that will fail, as shadow-cljs expects to find a file with JS syntax, which a .wasm
file is not
No, in fact, this is in line with the last thing we discussed - where we left this was, with the race condition introduced by webpack, this may be impossible, but in fact if I can load the wasm asynchronously and pass it to the library itself that needs it to be initialized, it might work, without needing any kind of special bundling from shadow-cljs or webpack or anything.
I can try to dig up that thread but I'm reasonably certain that's where we left it, so that's why I'm trying to go back and remove the webpack bundling.
thats what led you to webpack in the first place. shadow-cljs cannot process this. webpack can, but implies that the loading mechanism becomes async
yes, exactly. that would be an option, but it was a hypothetical for something that doesn't exist in automerge
That's why I said "if I can load the wasm asynchronously and pass it to the library itself" ...
I'm trying to figure out how I would remove all references to automerge in the code, since this is an existing codebase that goes back years (but of course used a different version).
I don't see any of my debugging logs get emitted that would occur when I try to do something with the module ...
ok, let me put it another way. some of the transitive dependencies brought in by your automerge require ends up doing import ... from "./automerge_wasm_bg.wasm"
which shadow-cljs is trying to process but cannot
and since its in those files you cannot configure or remove it, well unless you are willing to rewrite automerge
Ok, so if I understand correctly then, since this just happens as a byproduct of that require, there's actually no workaround, unless I have a local version of automerge that doesn't perform such an import automatically.
the screenshot of the JS example you posted isn't maybe clear enough about what structure you'd need for CLJS, so let me give a second snippet to complement
import * as Automerge from "@automerge/automerge";
let wasm = await fetch_util("/some/location/automerge.wasm");
let doc = Automerge.init(wasm);
this would enable YOU to just take that wasm
file out of node_modules
, put it on your server, load it via fetch
or whatever in CLJS and start automerge that way
Yes, so like I mentioned, they do have such a facility in automerge, and it is in use by something else already (not a clojure project) ...
And I think the fact that the main project imports stuff from the automerge-wasm project results in this breaking for us from a cljs perspective.
Anyway, I do understand what you're saying. Basically the automerge project itself can't actually have project references to the wasm project, or they'll get loaded transitively.
yes, as this is a non-standard feature not all bundlers support. and no browsers at all.
so basically expecting you to use webpack, but for webpack to do all this has to make the entire loading process async
but the code using that require is expecting it to be available, so it will fail regardless
as far as I understood it they *used* to have this, but removed it in favor of the package dealing with it internally
since there is a non-optional import * as wasm from "@automerge/automerge-wasm";
in line 55 here https://unpkg.com/browse/@automerge/[email protected]/dist/mjs/stable.js and the line after that immediately using it. no chance to do anything async inbetween.