Fork me on GitHub
#shadow-cljs
<
2017-11-26
>
Malte11:11:30

Hi, currently I'm playing around with shadow-cljs and still don't completely grasp its dependency management (especially the interplay between cljs and npm libs). When I bootstrap a leiningen app (e.g. with figwheel) and add rum as dependency, I can start my app with lein figwheel right away and all required dependencies are downloaded automatically. On the other hand, when I add rum as a dependency to shadow-cljs, I have to separately include the official js react dependencies in the project's package.json as well (e.g. done here: https://github.com/thheller/shadow-cljs-template). If I don't, I receive an The required JS dependency "react" is not available, it was required by "cljsjs/react.cljs" (`cljsjs/react` is a dependency for rum) error. Why is that? I guess I'm not really understanding how leiningen and shadow-cljs solve the installation of dependencies internally, especially when it comes to cljsjs-libraries (which we don't really need in shadow-cljs anyways, right?).

thheller11:11:44

shadow-cljs uses npm to manage the JS dependencies. so you npm install react.

thheller11:11:47

not all CLJS project (eg. rum) properly declare their :npm-deps and will still use cljsjs

thheller11:11:19

so its a matter of projects not declaring the deps, they should be automatically installed once declared properly

thheller11:11:30

until that point though it will remain a bit manual

thheller12:11:45

oh if you use the template run npm install. it already has everything properly setup.

thheller12:11:58

lein templates just don’t run that command for you

thheller12:11:14

https://github.com/shadow-cljs/lein-template thats the template btw. deleted the old fork.

Malte12:11:09

Thanks a lot for your quick response 🙂 So that's already a lot clearer. Just for comparison: Why doesn't leiningen need this extra step of installing the react js dependency?

thheller12:11:33

because rum uses cljsjs.react which is the re-packaged npm package. so its not using npm but rather the 3rd party package. https://github.com/cljsjs/packages/tree/master/react

thheller12:11:17

shadow-cljs uses the npm package directly, skipping the re-packaged cljsjs.

Malte12:11:24

Ah, OK, so shadow-cljs is aware of cljsjs dependencies and can skip them automatically? That's really cool!

thheller12:11:29

it doesn’t strictly skip them, it just provides the mapping back to their original npm packages. https://github.com/thheller/shadow-cljsjs

thheller12:11:43

> The systems simply do not mix well and frequently conflict with each other. One library might use cljsjs.react while another uses the newer “react”. This would lead to two versions of React being included in your page.

thheller12:11:13

thats basically why I have to work around cljsjs packages, I don’t want any of those conflicts.

Malte12:11:32

I think I've understood it now. Thanks again for your time! I'll also have a look at your blog posts.