Fork me on GitHub

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?


@doglooksgood yes, that is intended. if you must have a fully standalone build I recommend post-processing the output with something like


thank you, I'll check ncc.


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?


npm install qs?


can't say more without more info


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$ is not a function
I've also tried following the refering format but had no luck with that either:
["d3-selection" :refer [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 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!


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 (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

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?


@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
[email protected]://localhost:8020/js/main.js:577:21
SHADOW_ENV</[email protected]://localhost:8020/js/main.js:1670:12
I've looked in the generated numbers.js and it seems to failing on this:
Tried googling about regeneratorRuntime undefined and found I can try this but I'm not really sure what it's doing
yarn add core-js
yarn add regenerator-runtime


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


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