Fork me on GitHub
#shadow-cljs
<
2021-06-09
>
ghaskins12:06:45

Hello all: im struggling to figure out how/when shadow-cljs may or may not automatically invoke npm install

ghaskins12:06:08

i have two projects and I cant spy a difference in their config, yet one will implicitly install npm deps and the other doesnt

ghaskins12:06:40

in the one that works, I observe this last line in the output

ghaskins12:06:42

$ lein dev
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
shadow-cljs - config: /Users/ghaskins/sandbox/git/mcp-login-ui/shadow-cljs.edn
shadow-cljs - running: lein run -m shadow.cljs.devtools.cli --npm watch app
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
running: npm install --no-save path@^0.12.7 chart.js@^2.9.4 react-chartjs-2@^2.11.1 react-sparklines@^1.7.0 react-password-strometer@^0.1.18 base64url@^3.0.1

ghaskins12:06:26

I do not get that in the project that doesnt work…in that project, manually running npm install fixes it

ghaskins12:06:30

im just looking for what triggers that difference in behavior

dpsutton13:06:58

as far as I know shadow never does this. There's a lein plugin that you are likely using here that does this. To me that plugin is a mistake, making everything more complicated

ghaskins14:06:41

That’s what I was wondering (and I agree) but I don’t seem to have a plug-in in either

ghaskins14:06:46

I’ll keep digging

dpsutton14:06:47

in the project.clj file you should see a shadow config, and also a lein-shadow (i think this is the name) plugin. This plugin allows you to keep the config in project.clj, the aim being that everything in a single file is beneficial. It installs npm deps, copies the shadow part to the standard shadow-cljs.edn location and then runs shadow for you. I see zero benefit and only downsides

ghaskins14:06:57

understood…i am not using lein-shadow in either project, afaict

ghaskins14:06:37

i do use lein, but I have a distinct shadow-cljs.edn (with lein=true) and package.json for each

dpsutton14:06:00

ah, sorry i went down the wrong path then

ghaskins14:06:02

i cant discern what is different, but one project auto- npm-installs for me

thheller14:06:42

@ghaskins installing npm dependencies is handled by libraries containing a deps.cljs file with :npm-deps listed

thheller14:06:47

otherwise you can disable it in shadow-cljs.edn but thats about it. maybe the other project has older dependencies that didn't yet have deps.cljs?

thheller14:06:12

@dpsutton shadow does install npm deps by default (for now, might make it optional at some point)

dpsutton14:06:33

oh is that recent? or have i just totally missed it

thheller14:06:47

no, that has been there for a very long time

dpsutton14:06:23

huh. i could have sworn when i watch an project in the past it would fail until i killed it and npm installed the deps.

dpsutton14:06:29

oh well. sorry for the noise

thheller14:06:56

well it can only install npm deps if they are listed in deps.cljs. many libs didn't do that for a while but nowadays most do

zackteo14:06:00

Hello, how do I do import 'leaflet/dist/leaflet.css'; from https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages I understand it should be (:require ["leaflet/dist/leaflet.css"]) ? But think I'm doing something wrong

thheller14:06:39

@zackteo css is not supported, so you need to handle it separately. might be enough to just copy the node_modules/leaflet/dist/leaflet.css to your public folder and include it

zackteo14:06:45

Right, how might I want to handle it actually?

thheller14:06:32

really depends on what kind of css setup you have. if you don't have one then the manual copy is probably good enough. if you have something like postcss setup just use that.

zackteo14:06:06

hmm okay will try

ghaskins15:06:14

> installing npm dependencies is handled by libraries containing a `deps.cljs` file with `:npm-deps` listed @thheller thats what I figured…what I cant reconcile atm is that both projects include the same cljs lib with a deps.edn, and then locally declare additional npm deps (such as react) in their local packages.json

ghaskins15:06:35

but for reasons I am still unsure about, one project implicitly runs npm install and the other does not

ghaskins15:06:51

im sure i have some difference I am not yet seeing

ghaskins15:06:57

ill keep digging

ghaskins15:06:27

i just wasnt sure if there was something to look for, like “oh, check :foo-bar in shadow-cljs.edn”

thheller15:06:19

@ghaskins shadow never runs an inital npm install for stuff listed in your package.json. that you have to do yourself

thheller15:06:46

shadow will only install npm deps that aren't already listed in package.json, so if you have those in them but did not run npm install then they won't be installed

ghaskins15:06:03

ah, that might be the hint I needed

ghaskins15:06:22

i think I know what is wrong, now

ghaskins15:06:26

ill report back

thheller15:06:32

basically the deps.cljs install is just a way to get missing things into your package.json

ghaskins15:06:58

yeah…the project that isnt working had previously been run with the defaults that creates packages-lock

thheller15:06:03

but yeah one npm install you'll need at least

ghaskins15:06:26

so the one that isnt working has a complete packages.json

ghaskins15:06:53

where “isnt working” is probably functionally correct

ghaskins15:06:28

i.e. the project that runs npm install has inadvertent novelty in the dep

thheller15:06:28

yeah unlike maven deps just listing the deps is not enough, need to actually run npm to install them

ghaskins15:06:30

ty, this is very helpful