Fork me on GitHub
#shadow-cljs
<
2021-12-13
>
tianshu07:12:03

I try to release a node-script , it works fine if I run node target/main.js. However, it seems to depend on node_modules . If I move target/main.js to somewhere else, it can't find required module anymore. Is it expected? How can I have a single file bundle?

thheller08:12:14

@doglooksgood yes, that is intended. if you must have a fully standalone build I recommend post-processing the output with something like https://github.com/vercel/ncc

tianshu08:12:56

thank you, I'll check ncc.

tianshu09:12:41

I have two apps, the smaller one can be bundled by ncc, the larger one can not. The error is Error: Cannot find module 'qs', looks like it still looking for something in node_modules. I tried to (js/require "qs"), but it seems doesn't work. Any suggestion on what should I do for further debugging?

thheller09:12:04

npm install qs?

thheller09:12:20

can't say more without more info

tianshu10:12:11

It's weird to because I can found qs in node_modules, I can even run target/main.js without any problems. So I have no idea which side cause the problem. Is the generated target/main.js has a statement that ncc can not recognize? or I just ran into a bug of ncc.

Daniel Stephens14:12:35

Hi all, I'm trying to use d3 in a cljs project. I'm working with shadow-cljs and I'm pretty new to both shadow-cljs and d3 so expecting this might be a stupid mistake. I did a yarn add d3 which seems to have done what I expected and added a bunch of d3 modules into node_modules/ I'm requiring d3 like so:

(ns browser
  (:require ["d3" :as d3]
            ["d3-scale" :refer [scaleLinear]]
            ["d3-shape" :refer [line]]))
and some of it appears to work, as I can run these refers in my REPL, and the interop functions as I'd expect
(-> (scaleLinear)
    (.domain #js [1 2]))
=> #object[scale]
However I can't seem to get any 'select' type functions to work, I tried using interop:
(.select d3 "#app")

Execution error (TypeError) at (<cljs repl>:1).
module$node_modules$d3$src$index.select is not a function
I've also tried following the refering format but had no luck with that either:
["d3-selection" :refer [select]]

(select)

Execution error (TypeError) at (<cljs repl>:1).
_select is undefined
Does anyone know how I'm meant to access the select function? I'm vaguely trying to achieve what they're doing here https://github.com/scotthaleen/cljs-d3-force-direct-graph/blob/master/src/haleen/fd/graph/core.cljs#L17 except they use the global context for d3 which doesn't work either for me, and from what I've read, shouldn't really be done. Thanks for any help!

metasoarous06:12:14

Hope I'm not derailing too extensively here, but have you looked at Vega or Vega-Lite for data visualizations? Vega-Lite is a bit higher level, but also quite a bit higher leverage. If you need to do something very precise or custom, Vega is extremely capable (e.g. someone once literally built pacman in Vega). Both are very well supported by a number of Clojure tools/wrappers, including https://github.com/metasoarous/oz (which I maintain), Hanami, darkstar, notespace, clerk, etc. As data APIs complete with a dataflow model for dynamic computations and interaction, they're also extremely declarative, and mesh very well with the Clojure philosophy. Obviously, if you want/need to use d3 for some very specific reason, then go right ahead. But if you just need to get some shit done, you may have an easier time using one of these libraries.

👍 1
Daniel Stephens15:12:09

Hi @U05100J3V, appreciate the information, I hadn't heard of Vega and am new to the ecosystem as a whole so no real need to use d3, my main requirement currently is for a force-directed graph which looks supported so I will take a look, thanks!

👍 1
kenny16:12:12

Is there a way to hide deprecated var use warnings for a particular set of vars while still showing for vars not in that set?

thheller17:12:30

@dstephens do you get any errors during loading? see the browser console? I would expect things to exist but maybe something failed to load properly?

Daniel Stephens17:12:45

@thheller Yes, I have found some errors!

shadow-cljs - failed to load module$node_modules$d3_array$src$number js.js:74:16
shadow-cljs - failed to load module$node_modules$d3_array$src$bisect js.js:74:16
shadow-cljs - failed to load module$node_modules$d3_array$src$index js.js:74:16
shadow-cljs - failed to load module$node_modules$d3$src$index js.js:74:16
An error occurred when loading abc.js main.js:1672:15
[email protected]://localhost:8020/js/cljs-runtime/module$node_modules$d3_array$src$number.js:5:400
[email protected]://localhost:8020/js/cljs-runtime/shadow.js.js:34:18
[email protected]://localhost:8020/js/cljs-runtime/module$node_modules$d3_array$src$bisect.js:1:521
[email protected]://localhost:8020/js/cljs-runtime/shadow.js.js:34:18
[email protected]://localhost:8020/js/cljs-runtime/module$node_modules$d3_array$src$index.js:17:485
[email protected]://localhost:8020/js/cljs-runtime/shadow.js.js:34:18
[email protected]://localhost:8020/js/cljs-runtime/module$node_modules$d3$src$index.js:1:164
[email protected]://localhost:8020/js/cljs-runtime/shadow.js.js:34:18
[email protected]://localhost:8020/js/cljs-runtime/shadow.js.js:59:20
@http://localhost:8020/js/cljs-runtime/abc.js:2:48
[email protected]://localhost:8020/js/main.js:577:21
SHADOW_ENV</[email protected]://localhost:8020/js/main.js:1670:12
@http://localhost:8020/js/main.js:2360:12
I've looked in the generated numbers.js and it seems to failing on this:
regeneratorRuntime.mark(numbers)
Tried googling about regeneratorRuntime undefined and found https://stackoverflow.com/questions/53558916/babel-7-referenceerror-regeneratorruntime-is-not-defined I can try this but I'm not really sure what it's doing
yarn add core-js
yarn add regenerator-runtime

thheller17:12:14

looks like you are using an older shadow-cljs verison as well?

thheller17:12:25

the regenerator thing you maybe can fix by doing a (:require ["regenerator-runtime/runtime"]) before your d3 or other js requires

Daniel Stephens17:12:11

> older shadow-cljs verison Very likely, I was just trying to add a few things into a previously working (to the best of my limited knowledge) play project I had. Thanks, I'll try updating and adding that and see how it goes!

Daniel Stephens17:12:04

Thank you @thheller! 🎉

(.select d3 "#app")
=> #object[Selection [object Object]]

👍 1