Hello all: im struggling to figure out how/when shadow-cljs may or may not automatically invoke npm install
i have two projects and I cant spy a difference in their config, yet one will implicitly install npm deps and the other doesnt
in the one that works, I observe this last line in the output
$ 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
I do not get that in the project that doesnt work…in that project, manually running npm install fixes it
im just looking for what triggers that difference in behavior
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
That’s what I was wondering (and I agree) but I don’t seem to have a plug-in in either
I’ll keep digging
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
understood…i am not using lein-shadow in either project, afaict
i do use lein, but I have a distinct shadow-cljs.edn (with lein=true) and package.json for each
ah, sorry i went down the wrong path then
i cant discern what is different, but one project auto- npm-installs for me
@ghaskins installing npm dependencies is handled by libraries containing a deps.cljs
file with :npm-deps
listed
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
?
@dpsutton shadow does install npm deps by default (for now, might make it optional at some point)
oh is that recent? or have i just totally missed it
no, that has been there for a very long time
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.
oh well. sorry for the noise
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
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
@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
Right, how might I want to handle it actually?
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.
hmm okay will try
thanks!
> 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
but for reasons I am still unsure about, one project implicitly runs npm install and the other does not
im sure i have some difference I am not yet seeing
ill keep digging
i just wasnt sure if there was something to look for, like “oh, check :foo-bar in shadow-cljs.edn”
@ghaskins shadow never runs an inital npm install
for stuff listed in your package.json. that you have to do yourself
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
ah, that might be the hint I needed
i think I know what is wrong, now
ty
ill report back
basically the deps.cljs install is just a way to get missing things into your package.json
yeah…the project that isnt working had previously been run with the defaults that creates packages-lock
but yeah one npm install
you'll need at least
so the one that isnt working has a complete packages.json
where “isnt working” is probably functionally correct
i.e. the project that runs npm install has inadvertent novelty in the dep
yeah unlike maven deps just listing the deps is not enough, need to actually run npm to install them
ty, this is very helpful