question, we are trying ot use (js/import ...) to dynamically load some code, but it fails claiming import$ isn't defined. when we try to use the import from the chrome console it works fine. why is shadow renaming the call to import$? and how we can use the import call from clojurescript in this way?
shadow_esm_import is defined for :target :esm builds. what are you using this with?
import gets munged by the cljs compiler to import$. technically not necessary, but not easy to change from shadow-cljs, so not its fault. 😉
nah wait it actually needs to be munged, otherwise the closure compiler will see it and try to compile it away
thats why the shadow.esm/dynamic-import thing exists in the first place
you can also get this to work in :target :browser but just making the :prepend "function shadow_esm_import(x) { return import(x); };", same as you already have basically
its 2025 so I recommend using :target :esm 😉
note that static analyzers like storybook will still trip over that since they're looking for literal import calls and ignore the wrapped function
thanks for the clarification, I tried :esm but things stopped working, so I'll keep the hacky way for now. @vale that's fine for our case, we are building a platform and wanna have external code developed by different teams to load, the whole environment is in our control, so I think it should be fine for the time being (at this stage is mostly a POC, we may get back to this if the idea moves forward)
what things stopped working? i haven't had issues using :esm
I haven't tried to debug, but once change, nothing was loading at all, so we just reverted right away
might still be "cheaper" to look into that than struggling with the alternatives
note that :esm also has (:require ["esm:/path/to/other.js" :as foo])) meaning it can require esm normally (and doesn't need dynamic import), just in case you are always loading the file anyway
I should really write an updated code splitting guide for esm as well. generally :esm is much better than :browser pretty much always 😛
we also tried the way described here: https://shadow-cljs.github.io/docs/UsersGuide.html#_dynamic_module_import but we get a different error:
Uncaught ReferenceError: shadow_esm_import is not definedwe were able to make it work via little dirty hack, in our HTML file we created something like:
function myImport(url) { return import(url); }
and this handles our needs just fine by calling (js/myImport). but I'm still puzzled on why shadow doesn't let me call js/import directly 🤔