Fork me on GitHub
#figwheel-main
<
2022-05-04
>
augustl09:05:49

is there an official recommended way to get cljsjs and bundle/webpack in figwheel main to play nicely? My assumption is that it's important to only have one of everything. So I removed all my cljsjs deps and added them to npm. And i also excluded cljsjs deps from reagent and other projects that pull them in transitively. Then I create cljsjs namespaces by hand, that sets global variables so that i.e. "React" is available globally when someone pulls in cljsjs.react. However, for some reason, the bundled output from figwheel seems to write things so that it's in the wrong order. I.e. a dependency that uses cljsjs.react seems to somehow execute before cljsjs.react is loaded in, and so "React" is undefined. Maybe I should think differently about this?

athomasoriginal12:05:10

Curious: which deps are available as CLJSJS, but not NPM that you’re interesting in?

augustl12:05:51

I'm going the opposite way actually, I'm getting rid of cljsjs and moving to using npm instead

athomasoriginal12:05:25

Right, so you’re going dep by dep instead of whole sale change?

augustl12:05:00

yeah, I plan to keep the old versjons of some dependencies I use around for now, and provide cljsjs for backwards compatibility, so I don't have to change the actual code, just the build step

👍 1
athomasoriginal12:05:34

My normal approach has been whole sale change because, from my experience doing this thing, I can just specify the same versions of the NPM packages and things are good. But, depending on the deps this may not be as straightforward? All good. Curiosity satisfied 🙂

augustl12:05:31

my main issue is a lack of understanding of what's going on and lots of manual trial and error 😄 But at least I can narrow it down now - I'm only going to try variants of having all cljsjs dependencies excluded (as mentioned in #figwheel-main)

👍 1
augustl09:05:23

https://figwheel.org/docs/npm.html does not mention that you should exclude cljsjs deps so maybe I'm over thinking it 🙂

augustl10:05:27

tldr: should you make sure to exclude transitive cljsjs dependencies when you combine figwheel main + bundling with webpack + cljsjs?

augustl11:05:59

not entirely sure... but it seems I've ended up in a situation where I have multiple instances of react around

augustl12:05:23

found it! You are indeed supposed to exclude cljsjs dependencies: > When compiling for production we should also, make sure that you aren’t including Cljsjs libraries that are being provided for by NPM libraries. We don’t want to be including libraries twice.

augustl12:05:54

is there any way to tell figwheel/webpack/.... that for the require cljsjs.react-select, it needs to load react and classnames first? I'm using auto bundling

augustl12:05:35

seems like my issue right now is that cljsjs.react-select includes a js file without any goog.require and goog.provide etc, so figwheel/webpack/... has no idea that it needs React to be available, and so I get errors about React being undefined when I run my bundled script

augustl12:05:07

(note that I'm not using cljsjs.react-select from upstream, I'm using a forked version, so maybe something is simply missing from this fork)

augustl12:05:44

I guess that it's a problem that I'm using npm and I've removed all cljsjs deps, except that one cljsjs dep that is an internal fork. So I am in fact still using cljsjs alongside npm

augustl13:05:02

ok... that was it 😄 The fact that this was an internally forked module made me blind to the fact that I was including a cljsjs module alongside npm modules. I added the forked module as a npm dependency instead and BOOM it works partyparrotpartyparrotpartyparrotpartyparrot

augustl13:05:36

tldr: when you combine cljsjs with bundling npm modules in figwheel main, remove and exclude all cljsjs dependencies. Everything has to come from package.json.

augustl13:05:35

I believe the issue is that cljsjs modules are missing important goog.require and goog.provide statements, which causes the cljsjs module to be included in the bundle at the wrong location where required modules aren't yet available

augustl13:05:59

</rubber-ducking-session>

duckie 1