shadow-cljs 2025-04-23

Dustin Getz (Hyperfiddle) 2025-04-23T20:58:08.734429Z

hi, I am trying to configure shadow to not process foreign requires and just pass them through, so that an out of band bundler (e.g. webpack) can process them. I've read the shadow docs closely and tried :js-options {:js-provider :import} as well as :js-provider :external (in the screenshot). but shadow still rewrites the js-require into a shim. What am I doing wrong?

Dustin Getz (Hyperfiddle) 2025-04-24T13:47:15.987929Z

that file contains a reference to shadow$bridge which is not defined at runtime and therefore crashes

shadow$bridge is provided by the :external-index file after that was processed by webpack. you need to load that before the CLJS output is loaded

Dustin Getz (Hyperfiddle) 2025-04-24T13:49:16.004859Z

the shadow config in my screenshot does not produce external-index

:external only works with the :browser target

for :esm use :js-provider :import, but that means the entire output needs to go through webpack, which isn't ideal. :browser with :external is a bit more forgiving

👀 1
Dustin Getz (Hyperfiddle) 2025-04-24T13:56:17.463519Z

if i use :target :esm + :js-provider :import, and process with webpack, i get dustingetz.root.js:6 Uncaught TypeError: shadow.esm.esm_import$dustingetz$ts_page.hello_ts is not a function however the shim does evaluate:

import "./cljs_env.js";

import * as esm_import$dustingetz$ts_page from "dustingetz/ts_page";
goog.provide("shadow.esm.esm_import$dustingetz$ts_page");
shadow.esm.esm_import$dustingetz$ts_page = esm_import$dustingetz$ts_page;
and therefore shadow.esm.esm_import$dustingetz$ts_page is defined as Module {__esModule: true, Symbol(Symbol.toStringTag): 'Module'}, which indeed is not a function

well yeah. that is the import *?

is the JS actually exporting this? can't see that part

Dustin Getz (Hyperfiddle) 2025-04-24T13:58:41.575949Z

oh my, i have found a major typo in userland, you are correct

Dustin Getz (Hyperfiddle) 2025-04-24T14:01:04.262079Z

it works, thank you for the support

👍 1

https://github.com/jaidetree/tasky/blob/e063511423f80fea11493906d4a24a5e34db4db9/frontend/shadow-cljs.edn#L8 Got a working setup leveraging vite for bundling. It's like 80% of what I want. Just thought it might be useful to compare 🤷‍♂️

FWIW

:release    {:compiler-options {:optimizations :advanced
                                        :infer-externs :auto}
you don't really need. thats the default.

That makes sense, I was playing around with those values when exploring my more ideal setup: cljs -shadow-cljs > node esm -vite-> browser JS but couldn't get the repl\live reload working reliably so went with the external js-provider path

yeah things get tricky with repl/hot-reload if things have to go through vite first

dunno how to make that work 😛

Haha same 🤷‍♂️

I hope I don't come off as unappreciative though, I've mostly really enjoyed working with shadow-cljs since 2018. I feel fortunate you took the time to make it and publish it 🙂

did you look at the actual shim? its just a helper, to do what you want

all good. I mostly enjoyed working on it 😉 solving my own problems after all

❤️ 1