Fork me on GitHub
#clojurescript
<
2018-03-19
>
Dormo01:03:39

I'm having some trouble with :npm-deps. Seems to install everything fine, but when I go to require it I get Uncaught Error: Undefined nameToPath for video.js

Dormo01:03:42

I've tried using (:require [video.js], (:require [video.js :as videojs]), and (:require ["video.js" :as videojs])

Dormo01:03:26

i got it working with another library, so i'm wondering if it might have something to do with the period in the library name.

Dormo02:03:35

app:cljs.user=> (:require video.js)
#object[ReferenceError ReferenceError: video is not defined]

mfikes02:03:29

@vheuken At the REPL, you'd type

(require 'video.js)

mfikes02:03:45

(The :require variant is used in ns forms.)

joshkh11:03:01

i have a cljs project that includes a dependency from npm like so and everything compiles fine:

{:npm-deps {:highlight.js "9.12.0"} :install-deps true}
https://github.com/joshkh/im-tables-3/blob/codegen/project.clj#L74-L75 i also have a larger project that includes this cljs project as a dependency, however the parent project fails to build because the node module doesn't install itself:
Failed to compile "resources/public/js/compiled/app.js" in 22.878 seconds.
----  Could not Analyze  resources/public/js/compiled/im_tables/views/dashboard/manager/codegen/main.cljs  ----
  No such namespace: highlight.js, could not locate highlight/js.cljs, highlight/js.cljc, or JavaScript source providing "highlight.js" 
i've tried adding :install-deps true to the parent project's build configuration with no luck. any ideas? šŸ™‚

joshkh11:03:51

(both projects are on the same version of clojure and clojurescript)

juhoteperi12:03:53

@joshkh The library only has :npm-deps defined on project.clj? That won't have any effect on apps using the library, Lein options (like cljsbuild) don't work like that.

joshkh12:03:26

hmm yeah, i didn't think they would. if a library has project level deps then they're installed when that project is required elsewhere. npm deps are defined at the cljsbuild level and so they don't bubble out.

juhoteperi12:03:27

I'd recommend just adding both :npm-deps and :install-deps to the parent project, then it is obvious that the specified npm dependency will be used.

juhoteperi12:03:28

However, this is probably not documented anywhere currently, but you can define :npm-deps on library's deps.cljs file (same place where foreign libs define :externs etc.) and that will be read by Cljs compiler when using :install-deps

joshkh12:03:28

that's what i ended up doing. it feels a little hacky though, yeah? you have to know that one of your dependencies has a node dependency, then manually lift it up into your project.

joshkh12:03:30

oh interesting. i'll look into that šŸ™‚ thanks

borkdude16:03:45

How can I a turn on instrumentation of all fdef-ed functions? https://cljs.github.io/api/cljs.spec/instrument-all seems to be removed?

borkdude16:03:09

testingā€¦

borkdude16:03:41

We have one init function for dev and one for prod. I put this in the init function for dev:

(s/check-asserts true)
(stest/instrument)
Does that make sense?

borkdude16:03:17

yay šŸ˜„

mfikes16:03:39

@borkdude FWIW, ClojureScript is a little behind Clojure with respect to precisely how stest/instrument behaves, but I suspect it won't matter for common use cases. Captured here https://dev.clojure.org/jira/browse/CLJS-2665

borkdude16:03:14

as long as Iā€™m getting an error Iā€™m fine

borkdude16:03:34

refactoring is easier that way

tungsten19:03:45

Has anyone here successfully used a react component with :npm-deps/:install-deps compiler options?

tungsten19:03:04

As far as I can tell cljsbuild does absolutely nothing when it is given those options

justinlee19:03:48

@bfast Iā€™ve spent many hours trying and failed and never found anybody who could help me. The three approaches that seem to reliably work with the current state of the art are (1) :foreign-libs (2) the ā€œdouble bundleā€ approach with webpack, (3) shadow-cljs. I prefer (3) because you just install stuff using npm and import directly, but some people would prefer to stay with their familiar lein/boot setup.

tungsten19:03:55

perhaps compiling the react component I want with webpack and then adding it as a foreign lib is the easiest way

tungsten19:03:10

I have to say, this is a huge miss in the CLJS world... If I figure this out I am definitely writing a tutorial

justinlee19:03:30

definitely check out shadow-cljs. it solved a lot of my pain points. as for :npm-deps I understand there are lots of improvements in the pipeline.

tungsten19:03:01

Thanks. Shadow-cljs isn't really an ideal option at this point because the rest of the project is tied into leiningen

thheller19:03:24

@bfast shadow-cljs works fine from inside leiningen šŸ˜‰

Roman Liutikov19:03:27

I found ā€œdouble bundleā€ is a good approach when you have shared JS dependencies between multiple cljs projects. Browser caches js bundle once and all apps can reuse this dependency from the cache.

oVerde19:03:54

Beginner here!

oVerde19:03:12

With garden am I supposed to have a .css file output?

oVerde19:03:18

If so, how?