What might cause a ; (err) Property 'module$mylib$lib' doesn't exist in the following ns declaration?
(ns myns.temp
(:require
["/mylib/lib" :refer (myfn)]))
the file lib.js is detected (I get an error if I change the name to a non-existing file) but I can't require it with the above method
the contents of lib.js are:
const myfn = () => console.log("hello world!");
export { myfn };looks fine to me
hm, the error is appearing with react-native as a target, am testing whether it happens with browser too
why are you reaching for JS in this case? this JS integration is well known to cause issues and is far from smooth unfortunately. usually better to let react-native process the JS stuff
I have a melange project that outputs some javascript files and I'm trying to import these
by "let react-native process the js stuff" do you mean putting the javascript files in the react-native project root?
good question. its been so long since I looked at anything react-native. can't even remember 😛
(def mylib (js/require "./mylib.js")) in the code
whereas the ./mylib.js path used is relative to the output files of shadow-cljs, so more likely ../mylib.js unless you happen to generates those files into the same folder as shadow-cljs :output-dir
then (.myfn mylib) to call the fn
ah I see, tyvm for the answer I'll test this out
just confirming that the issue doesn't arise when the target is the browser. will now test out your suggestion
that ended up working!
tyvm for the help!
I'm getting a bit of inconsistent behaviour wrt js/require between two projects, but it's obviously because I have something somewhere that's not the same, any way I can introspect what is the working directory from which js/require grabs files?
edit: turns out repl/devtools js/require will not detect the file if it was not required during build! solved
First off, thanks for shadow-cljs, it’s been a huge help 😄!!
We’re trying to optimize our bundle size using :js-provider :external, which is working great with tree-shaking. The only downside is that all externals end up in a separate js-file that needs to be loaded before the main app can load. Since we’re currently using shadow.lazy, a lot of big libraries (like a barcode scanner via phone-camera) are only needed on specific user actions. Loading this eagerly will load a lot of unnecessary things.
Is there a way to control which libs are handled by shadow and which externally? Would be nice to cherry-pick the ones we want to tree-shake. Couldn’t find anything about that in the docs. Is that possible, or is there another approach to tree-shaking?
unfortunately there is no answer for this currently
the problem isn't so much on the shadow-cljs side, but rather the JS side and getting output thats actually usable in the way shadow-cljs would understand
well, there would need to be quite a bit of restructuring on the shadow-cljs side too
currently my rough idea is using :target :esm and making that work with :external
but that has its own problems ... so not much progress yet
:external kinda is all or nothing kinda deal, very hard to only bundle partial stuff
@thheller Got it, thanks! I searched Slack and GitHub but didn’t find anything. The issue you mentioned is exactly what I was looking for. Thanks for the answer and extra explanation 🙂! Too bad it doesn’t work, but no big deal. I’ll find a workaround.
the tree shaking parts make this all rather complicated. loading something dynamically, but statically figuring out what of that is needed is kinda tough 😛
I can completely understand 😄. I’m already amazed what magic you’re able to pull of with shadow-cljs!