shadow-cljs

VardriPoise 2025-06-30T13:05:25.081079Z

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 };

thheller 2025-06-30T13:22:39.539259Z

looks fine to me

VardriPoise 2025-06-30T13:26:03.081419Z

hm, the error is appearing with react-native as a target, am testing whether it happens with browser too

thheller 2025-06-30T13:32:21.012329Z

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

VardriPoise 2025-06-30T13:33:58.810069Z

I have a melange project that outputs some javascript files and I'm trying to import these

VardriPoise 2025-06-30T13:34:16.228739Z

by "let react-native process the js stuff" do you mean putting the javascript files in the react-native project root?

thheller 2025-06-30T13:35:18.589239Z

good question. its been so long since I looked at anything react-native. can't even remember 😛

thheller 2025-06-30T13:37:00.220359Z

(def mylib (js/require "./mylib.js")) in the code

thheller 2025-06-30T13:37:18.769039Z

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

thheller 2025-06-30T13:38:02.690199Z

then (.myfn mylib) to call the fn

VardriPoise 2025-06-30T13:38:41.421009Z

ah I see, tyvm for the answer I'll test this out

VardriPoise 2025-06-30T13:40:24.001459Z

just confirming that the issue doesn't arise when the target is the browser. will now test out your suggestion

VardriPoise 2025-06-30T14:07:37.410409Z

that ended up working!

VardriPoise 2025-06-30T14:07:40.400909Z

tyvm for the help!

VardriPoise 2025-06-30T14:46:07.498589Z

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

2025-06-30T19:55:45.769439Z

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?

thheller 2025-07-01T06:17:50.783069Z

unfortunately there is no answer for this currently

thheller 2025-07-01T06:18:20.499719Z

https://github.com/thheller/shadow-cljs/issues/1162

thheller 2025-07-01T06:18:48.619389Z

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

thheller 2025-07-01T06:19:22.122279Z

well, there would need to be quite a bit of restructuring on the shadow-cljs side too

thheller 2025-07-01T06:20:25.267249Z

currently my rough idea is using :target :esm and making that work with :external

thheller 2025-07-01T06:20:57.666399Z

but that has its own problems ... so not much progress yet

thheller 2025-07-01T06:22:04.254549Z

:external kinda is all or nothing kinda deal, very hard to only bundle partial stuff

2025-07-01T07:43:24.764959Z

@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.

thheller 2025-07-01T07:49:32.080719Z

the tree shaking parts make this all rather complicated. loading something dynamically, but statically figuring out what of that is needed is kinda tough 😛

2025-07-01T07:50:12.361549Z

I can completely understand 😄. I’m already amazed what magic you’re able to pull of with shadow-cljs!