Fork me on GitHub
#clojurescript
<
2017-10-24
>
Aron01:10:16

how to use a module from npm that only exports an unnamed function?

johnjelinek01:10:39

is it possible to transpile some cljs to js without the Google Closure stuff?

johnjelinek01:10:10

I want to simply turn my cljs file into a js equivalent that I can run with cucumber at the CLI

johnjelinek01:10:48

these transpiled js files wouldn't have an entrypoint

Aron01:10:13

what do you mean "without google closure?"

johnjelinek02:10:59

ehh, ya, that wouldn't make any sense because output looks something like this:

// Compiled by ClojureScript 1.9.946 {:target :nodejs}
goog.provide('steps.foo');
goog.require('cljs.core');
cljs.core.enable_console_print_BANG_.call(null);
cljs.core.println.call(null,"Hello world");

johnjelinek02:10:07

and everything depends on those being there

johnjelinek02:10:09

what I want is like, how in typescript, I can do typescript things and it transpiles to es6 without adding extra libs -- I want that with cljs, because in this case, it's the transpiled output that gets evaluated by the runner: cucumber-js binary

johnjelinek02:10:21

(which is a node CLI app)

johnjelinek02:10:22

I can follow the folder structure and translate that nodejs into cljs, but then when it comes time to build the cljs to run cucumber against the output, it will fail

Aron02:10:01

i have no idea 🙂

Aron02:10:56

for 3 days i've been trying to setup a cljs devenv, and i thought i had it, but no. some npm modules work, some npm modules don't work, everything just dies silently during compile

Aron02:10:17

actually, it starts some node processes that hang with 100% cpu until i killed them

Aron02:10:30

anyway, what's better way to spend the time between 2 AM and work than debug this, right?

Aron03:10:34

not like i need sleep, or anything

Aron05:10:57

what is a "transitive dep"?

reedho05:10:35

dependencies that are not directly required by our project

reedho05:10:44

e.g. dependencies that are required by one or more of our project dependencies 🙂

Aron05:10:48

i see, thanks

Aron05:10:43

i don't know why i can't require my npm module. it works fine from js but when i try to use it from cljs, the compile never finishes

Aron05:10:50

well. never. i waited more than 15 minutes.

Aron05:10:52

and i am guessing this happens because my module exports an anonymous arrow function

reedho05:10:31

umm, good to know. Its still alpha feature i thought

Aron05:10:16

i am even guessing what the bug is, the temp name is colliding with an already existing function. (i give 0.001% chance for this to happen, but would explain 100% so i like it :D)

Aron05:10:49

yeah, i was wrong, that didn't help at all.

Aron05:10:07

again, i am out of ideas, as usually is with the case with clojure

Aron05:10:11

maybe if you are curious, you can try installing it yourself and check what might be the issue https://www.npmjs.com/package/geta-random-word use version 1.2.0

dimovich08:10:56

I tried using it from npm, but it gets stuck compiling (node is eating the CPU)...

dimovich08:10:16

maybe try using it with :foreign-libs ?

Aron10:10:19

i will google :foreign-libs, thanks

dimovich07:10:49

@dhruv1 I'm checking the js extern name by opening the browser and writing in the browser console: window.<some words from lib name>

dimovich07:10:44

include them in your ns like so (:require [cljsjs.react-draggable])

dimovich07:10:45

@dhruv1 then (def react-drag (r/adapt-react-class js/ReactDraggable))

dhruv113:10:43

@dimovich thanks. i’ll give that a shot now

madstap13:10:11

I'm getting Uncaught Error: Undefined nameToPath for prismic_javascript when trying to use :npm-deps

dhruv113:10:56

@dimovich still no luck for me.

(ns test.draggable
  (:require [cljsjs.react-draggable]
            [reagent.core :as r])) 
(def react-drag (r/adapt-react-class js/ReactDraggable)) error: #object[ReferenceError ReferenceError: ReactDraggable is not defined]

hlolli14:10:25

@dhruv1 have you tried in reagent [:> js/ReactDraggable [:div ...]]

dhruv114:10:10

i am sorry i haven’t. I am very new to web dev and the re-frame / reagent “framework”

hlolli14:10:32

otherwise try typeing js/ReactDraggable into the brepl and see if you ged reference error, then it means your code is not loading or figwheel (in case you're on figwheel) wasn't able to compile.

dhruv114:10:40

i will try it out using reagent. but anytime i reference js/ReactDraggable i get a reference error. when i run (cljs-repl) in my cider-repl, react-draggable is compiled and file is generated resources/public/js/compiled/out/cljsjs/react- yes i agree that the ReactDraggable is then not being loaded

hlolli14:10:41

it could be that what you're doing r/adapt-react-class is correct, I just never used it, the :> is maybe a syntax sugar for just that function

dhruv114:10:08

when i use MaterialUI js library, (r/adapt-react-class works fine

dhruv114:10:38

and weirdly MaterialUI library gets loaded and I am able to use it :S

hlolli14:10:40

hmm ok, is it defined when you type ReactDraggable into the developer console of the browser?

dhruv114:10:47

it’s not.

dhruv114:10:05

and currently i am trying to figure out why

hlolli14:10:03

that's really strange. Try deleteing all the js artifacte (eg. /out) and restart all the tooling you use, be it clojure/figwheel etc.

dhruv114:10:56

i did. i’ve been constantly running lein clean and restarting my repl. running lein clean cleans out the resources/public/js/ folder

hlolli14:10:38

I initially made the cljsjs package for ReactDraggable, and I see much has changed. Let me try to require it, and I let you know if I can.

dhruv114:10:52

this is weird and i am not sure what’s going on but going through my chrome console i sometimes see this error

Uncaught TypeError: goog.net.jsloader.load is not a function
    at file_reloading.cljs?rel=1508855444416:243
    at figwheel$client$file_reloading$reload_file (file_reloading.cljs?rel=1508855444416:252)
    at figwheel$client$file_reloading$blocking_load (file_reloading.cljs?rel=1508855444416:271)
    at file_reloading.cljs?rel=1508855444416:281
    at file_reloading.cljs?rel=1508855444416:279
    at figwheel$client$file_reloading$state_machine__40235__auto____1 (file_reloading.cljs?rel=1508855444416:279)
    at figwheel$client$file_reloading$state_machine__40235__auto__ (file_reloading.cljs?rel=1508855444416:279)
    at cljs$core$async$impl$ioc_helpers$run_state_machine (ioc_helpers.cljs?rel=1508855441624:35)
    at cljs$core$async$impl$ioc_helpers$run_state_machine_wrapped (ioc_helpers.cljs?rel=1508855441624:39)
    at ioc_helpers.cljs?rel=1508855441624:48
    at channels.cljs?rel=1508855438884:74
    at cljs$core$async$impl$dispatch$process_messages (dispatch.cljs?rel=1508855438792:19)
    at <anonymous> 

dhruv114:10:05

and there are times i don’t see that error.

dhruv114:10:25

@hlolli sweet thanks!!

hlolli14:10:19

that was ackward, it seems that I can't start my project anymore, few more mins.

hlolli14:10:35

ok, I removed react-draggable and I can start my project again.

hlolli14:10:49

It's clearly a bug there in the newest version

hlolli14:10:05

I try it still again...

dhruv114:10:13

hey no worries.

dhruv114:10:27

i am now able to get it to work.

hlolli14:10:12

ok, strange, I get Undefined nameToPath for react

dhruv114:10:21

i think the problem was i wasn’t requiring it in the mytest.core ns

dhruv114:10:45

i added it in there and and restarted my repl after doing a clean and now i can see it in my chrome console

dhruv114:10:05

this is the version i’m using [cljsjs/react-draggable “3.0.3-0”]

hlolli14:10:10

ah ok, glad it works for you.

dhruv114:10:30

which version are you using?

hlolli14:10:40

Yes I tried that too, same version.

dhruv114:10:10

i am also using figwheel and nrepl for my development.

hlolli15:10:00

well nevermind, it could be totally unrelated.

madstap16:10:37

I'm trying to grok :npm-deps and I can't get the simplest possible example to work

madstap16:10:15

I have a build.clj file, like in the cljs quickstart which looks like this

madstap16:10:07

And I get that error in the js console. Am I missing something? From reading https://anmonteiro.com/2017/03/requiring-node-js-modules-from-clojurescript-namespaces/ it seems like this should work.

admay16:10:36

@madstap it looks like a few people in the comments had problems getting that code to work. Have you looked at the Node integration docs from http://clojurescript.org? https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules

madstap17:10:18

With that one I get another error: Exception in thread "main" java.lang.AssertionError: Assert failed: cljs.analyzer/foreign-dep? expected symbol got "react-dom/server"

anmonteiro17:10:34

@madstap are you sure you’re not on an old version of ClojureScript that doesn’t support all this?

madstap17:10:05

Pretty sure, I just downloaded the jar, but let me double check

madstap17:10:01

Again, and I got the expected symbol error again

madstap17:10:17

I tried nuking node_modules and the contents of out and now I get

[eval]:1
let fs = require('fs');
^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at Object.exports.runInThisContext (vm.js:53:16)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:410:26)
    at node.js:578:27
    at nextTickCallbackWith0Args (node.js:419:9)
    at process._tickCallback (node.js:348:13)

madstap17:10:06

Which I have seem intermittently when trying to get stuff working. Below that I still get the expected symbol error

anmonteiro17:10:21

@madstap I would recommend upgrading Node.js, you may be on an old version

madstap18:10:42

Ok, I did that and the error message changed: Uncaught Error: Undefined nameToPath for react

admay18:10:32

Hmm… it seems like no matter what you put in there, the nameToPath is going to be undefined. What are you using to build? Leiningen, boot, java -jar?

madstap18:10:22

I was using lein with figwheel and all that stuff, but I took a step back and just used the cljs quickstart way (`java -jar ...`). I got it to work now with that by nuking everything, gonna try it on my real project now

admay18:10:43

any idea where the problem was?

madstap18:10:14

@admay Things seem to be working now, I suppose the problem was an outdated nodejs

escherize19:10:20

Looks like instrument doesn't exist in clojurescript 1.9.908. I checked in cljs.spec.alpha and cljs.spec.gen (which are the only two namespaces prefixed with cljs.spec I have loaded...) What gives? Is there still a way to instrument specs?

mfikes20:10:41

@escherize cljs.spec.test.alpha/instrument

vinnyataide21:10:06

Hello I'm having an inconsistency with my project on a windows machine. When I run the same project in the same computer in a linux box it works normally. I'm thinking that it has something to do with this $ symbol

Writing adzerk\boot_reload\static$\js\app.cljs to connect to ...

dimovich09:10:56

@U17CAUN2F I'm having the same issue... I suppose you're using app.cljs.edn config file?

vinnyataide21:10:13

@dimovich yes, without edn it works?

dimovich09:10:29

yeah... instead of specifying the build config in app.cljs.edn, do it in your boot or lein build config

dimovich09:10:14

I also feel that $ is messing with Windows

escherize21:10:28

@mfikes Thanks Mike, but is there some other dependency I need to be able to do that? I don't seem to have cljs.spec.test.alpha loaded in my repl.

escherize21:10:07

@mfikes Nevermind - I see now. I needed to require it.