Fork me on GitHub
#shadow-cljs
<
2020-03-24
>
teawaterwire10:03:10

i have this INFO warning with one module, i haven't noticed issues in my app so far but what could be the consequences of such an "invalid-required"

node: v11.13.0
shadow-cljs - server version: 2.8.51 running at 
shadow-cljs - nREPL server started on port 52448
[2020-03-24 11:42:40.454 - INFO] :shadow.build.npm/js-invalid-requires - {:resource-name "node_modules/eth-lib/lib/bytes.js", :requires [{:line 9, :column 193}]}

thheller12:03:03

typically thats some kind of dynamic require in JS, so that would always fail

teawaterwire13:03:03

got it, dynamic require, interesting line in that library 😅

if (typeof window !== "undefined" && window.crypto && window.crypto.getRandomValues) rnd = window.crypto.getRandomValues(new Uint8Array(bytes));else if (typeof require !== "undefined") rnd = require("c" + "rypto").randomBytes(bytes);else throw "Safe random numbers not available.";

thheller14:03:23

yeah thats specifically to stop bundlers from bundling the crypto package since dynamic requires are still pretty much an unsolved problem

teawaterwire14:03:07

make sense - thanks!

Ben Hammond14:03:35

I have a cljs/React front end that I have been hosting with the shadow-cljs :dev-http I have a clojure backend running on pedestal/jetty I am now at the point where I would like to establish a websocket connection between the two; Ideally I would like to serve the front-end from Pedestal server AND connect a shadow-cljs repl to this session; When I serve the html pages from pedestal however, I cannot get the cljs repl started; I get > No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code. I can see that shadow-cljs :run-dev somehow injects

 
into the webpage and I can see that Pedestal server does not do this and I presume that this is why it does not make a repl connection; Where does this repl websocket get injected? How can I get Pedestal server to do the same thing?

thheller14:03:56

@ben.hammond you don't need to configure pedestal in any way. the websocket connection is made to the shadow-cljs server which is completely separate

thheller14:03:17

this also has nothing to do with :dev-http. that is strictly serving static files only.

Ben Hammond14:03:11

oh so the REPL ws connection should be identical wherever the cljs files are server from

thheller14:03:30

the .js files can be served by pedestal as they are just files

thheller14:03:57

the websocket connection is made to the shadow-cljs server which is running on port 9630

👍 4
Ben Hammond14:03:27

ah right I see I see thanks!

wasser14:03:19

Hope everyone is well. I’m working with Higcharts using https://github.com/kirjs/react-highcharts and things are going fine until I want to use the “Sankey” style chart (https://www.highcharts.com/demo/sankey-diagram). This is provided in a separate JS file (https://code.highcharts.com/modules/sankey.js). The Highchart fiddle just shows adding the sankey.js to your html and it works. Except it doesn’t since I’m using the npm package. I can’t figure out how to get the react component to find this extra code/module. I added the sankey.js to the html and even tried https://github.com/clarketm/highcharts-more, but that package doesn’t seen to include Sankey. I keep getting “Error: Highcharts error #17: http://www.highcharts.com/errors/17/?missingModuleFor=sankey missingModuleFor: sankey” Has anyone figured out how to get this to work?

thheller15:03:56

@wasser you probably can import it from the highcharts npm module. check if you can find a sankey file in node_modules/highcharts

thheller15:03:52

dunno about the react parts though

mauricio.szabo16:03:21

Hi, I'm trying to use a node module on Shadow-CLJS, but it's not raising the error: '"module$node_modules$nrepl_client$src$nrepl_client is not defined"' The node module is nrepl-client, I'm trying to require it with ["nrepl-client" :as nrepl], shadow-cljs target is node-library

mauricio.szabo16:03:32

If I use js/require it works correctly

defa17:03:09

I’m having trouble with my production build (targeting the browser). When loading index.html in the browser I get an error in the JavaScript console: ReferenceError: Can't find variable foo where my init-function is foo.core/init . In development mode everything works find…

defa17:03:05

In shadow-cljs.edn I tried:

:modules    {:main {:init-fn foo.core/init}}
and
:modules    {:main {:entries [foo.core]}}
my index.html looks like this:
<html lang="en">
  <head>
	<!-- ... -->
    <script src="/js/compiled/main.js"></script>
  </head>
  <body>
    <div id="app"></div>
    <script>foo.core.init();</script>
  </body>
</html>

defa17:03:41

… and in foo/core.cljs I have:

defa17:03:48

(defn ^:export init []
...)

thheller19:03:38

do you get any JS errors during load?

thheller19:03:54

like any others I mean?

defa20:03:47

Yes, it happens during load…

TypeError: undefined is not an object (evaluating '$N.call')
	iO — main.js:1126:113
	cN — main.js:1128:348
	(anonymous function) — main.js:1061:406
	(anonymous function) — main.js:1061:441
	Global Code — main.js:1800
	
ReferenceError: Can't find variable: foo
	Global Code — 
where `
where line 18 of index.html is:
<script>foo.core.init();</script>

defa20:03:17

Solved. I used the --debug option when compiling my production code and it turned out that there was some debug code using cljs.pprint/pprint without explicitly requiring it. So shadow-cljs release foo --debug did the trick and produced some useful output to the JavaScript console in the browser to track down the problem. Instead of (evaluating '$N.call') in the logs above I got some hints to hat it was related to pprint

👍 4
wasser18:03:38

@thheller I found a sankey.js file in node_modules/highcharts/modules so tried adding ‘[“highcharts/modules/sankey.js”]’ to the namespace, but I still get the “error 17, missing module for sankey”. Do I need to add the dependency somewhere else?

thheller19:03:24

I have no idea sorry. maybe you need to initialize it somehow. highcharts probably has some docs for that?

wasser19:03:34

Thanks anyway. Maybe someone else has stubbled into this and got it sorted.

David Pham21:03:22

Did you try to put the file somewhere else?

David Pham21:03:48

Like where you have your usual highcharts dependency?

David Pham21:03:14

What about removing the .js at the end of your import?

wasser02:03:59

None of those (putting the js file someplace, adding it to the html, dropping the .js) worked - stil getting “Error 17”. I found another react lib to try which apparently includes the sankey stuff directly so I don’t get the “Error 17", but if fails in a different way: “undefined is not an object (evaluating ‘t.chart’)” Now I’m trying to get some source-maps, so I have a chance of figuring out what this issue really is (shadow-cljs noob).

thheller08:03:33

the issue likely doesn't have anything to do with shadow-cljs. I suspect that you just have to initialize the sankey module somehow. I can't tell you how though. the highcharts docs probably mention it with an example for npm. that you'd just need to translate.

wasser19:03:02

@thheller - right you are! pawing theough the docs for react-jsx-highcharts I found the all important call: [“highcharts/modules/sankey” :as addSankeyModule] ... (addSankeyModule Highcharts)

👍 4