Fork me on GitHub
#shadow-cljs
<
2020-06-21
>
thheller08:06:22

@currentoor forgot to ask which version you use? the ping behavior was definitely buggy in earler 2.10.x versions. make sure you are on 2.10.12

thheller19:06:32

can you open the UI and see if that sends ping/pong? or does that also not work?

currentoor21:06:48

i was able to open the UI, however i came into my office, which is a different network, and now it's working very robustly

currentoor21:06:14

thanks for considering though

currentoor21:06:00

strange that this only happens • on android device (android emulator and iOS device worked fine) • connected over lan • at my home network (office works) • for the shadow WS (my app's WS using sente works)

currentoor21:06:10

very mysterious but im just glad it's working now

thheller08:06:39

@rberger what does the browser console say? does it not actually rebuild anything? do you maybe have the file in a resources folder?

rberger03:06:04

Still having this issue that changes in the JS file does not trigger shadow in watch mode to rebuild. The Browser Console, the shell terminal running shadow-cljs -A:dev watch app, nor the webpage itself show any indication that a rebuild happens. The JS file is not in resources (other than the compiled output). I wasn’t quite sure what was meant in the guide (https://shadow-cljs.github.io/docs/UsersGuide.html#classpath-js) by: > The files must not be physically located in the same directory. The lookup for the file appears on the classpath instead. This is unlike node which expects relative requires to always resolve to physical files. So I tried all the permutations I could think of and none of them would trigger shadow-cljs watch to rebuild. Updating any CLJS file did as normal. Here is what I tried: 1. With the JS file in the same source tree (but not directory) as the cljs file requiring the JS file: deps.edn :path ["src"]

(ns visx.dashboard.antmedia
  (:require
   ["/visx/dashboard/antmedia/webrtc_adaptor.js" :refer [WebRTCAdaptor]]))
or
(ns visx.dashboard.antmedia
  (:require
   ["./antmedia/webrtc_adaptor.js" :refer [WebRTCAdaptor]]))
with the file layout:
├── package.json
├── shadow-cljs.edn
└── src
    └── visx
        └── dashboard
            └── antmedia.cljs
            |__ antmedia
                |__ webrtc_adapter.js
2. Or when the JS file is a different directory tree under src:
(ns visx.dashboard.antmedia
  (:require
   ["/js/dashboard/antmedia/webrtc_adaptor.js" :refer [WebRTCAdaptor]]))
├── package.json
├── shadow-cljs.edn
└── src
    └── visx
        └── dashboard
            └── antmedia.cljs
            |__ antmedia


    └── js
        └── dashboard
            └── antmedia
                |__ webrtc-adapter.js
3. Or when the JS is in a different tree but matching class path with updated :path: deps.edn: :path ["src/js" "src/cljs"]
(ns visx.dashboard.antmedia
  (:require
   ["/visx/dashboard/antmedia/webrtc_adaptor.js" :refer [WebRTCAdaptor]]))
or
(ns visx.dashboard.antmedia
  (:require
   ["./antmedia/webrtc_adaptor.js" :refer [WebRTCAdaptor]]))
├── package.json
├── shadow-cljs.edn
└── src
    [__ cljs
        └── visx
            └── dashboard
                └── antmedia.cljs
                |__ antmedia
    └── js
        |__ visx
            └── dashboard
                └── antmedia
                    |__ webrtc-adapter.js

thheller08:06:53

please stop shadow-cljs completely

thheller08:06:03

then run shadow-cljs watch <your-build> --verbose

thheller08:06:27

after the initial compile has finished run touch src/whever/the/file/is.js

thheller08:06:30

and post the full log

thheller08:06:39

it doesn't really matter where the file is. just put it into the same directory you are including it from. all this classpath juggling isn't useful or required

zilti10:06:28

I tried using shadow-cljs on a fresh Windows install today. I "installed clojure" using their new powershell script, and npm and GraalVM using Chocolatey (JAVA_HOME is set, and java is on the path; running clj works as expected). I did an npm install in my project and ran clj once so all dependencies are present. Then I tried to run npx shadow-cljs, but only get the error that the system can't find the path. What could that be?

David Pham11:06:52

Find the path of what?

zilti11:06:16

Yea no idea. That is all powershell tells me. "The system couldn't find the specified path".

David Pham12:06:42

I am sorry, I don't have a lot of experience with powershell. What could you try is to execute shadow-cljs directly by specifying the full path directly in powershell. I would recommend trying bash though 🙂

Oz11:06:34

did you install npx? also maybe whitespace in the path?

zilti11:06:44

yes, and just calling npx on its own shows the normal help text with the possible flags of npx

zilti11:06:57

No whitespace in the path

Oz12:06:30

npx shadow-cljs watch app suddenly doesn't recompile or reload my code when I save my soruces. I'm not sure what have changed. it might have been cosmic radiation. On the other hand, changes to shadow-cljs.edn are being watched correctly. Any idea how to debug this?

erik12:06:52

what is the relationship between the nREPL and the different JS contents of a chrome extension such as bg script and content scripts?

zilti14:06:08

Okay so npx shadow-cljs works fine outside of the project directory.

Lucy Wang15:06:57

@thheller With latest 2.10.12 I find a bug: each time I eval the ns form for a file, the functions defined in that ns is lost, calling them in the REPL results in errors like

------ WARNING - :undeclared-var -----------------------------------------------
 Resource: <eval>:1:2
 Use of undeclared Var my.ns/f1

thheller17:06:40

@wxitb2017 (ns my.ns) always just declares that ns. you need to (require 'my.ns) (in-ns 'my.ns) if you want to load and switch? that has always been that way though.

Lucy Wang01:06:57

@thheller nope, for a better example, take this ns as an example

// project/lib.js
(ns project.lib)

(defn f1 [])
So this ns has a f1 var. But if I eval the ns form again, and try to catch f1 , it would throw the error I pasted above.

thheller08:06:40

this is not a better example. please use shadow-cljs node-repl or browser-repl and post everyh single step you do to get to the error

Lucy Wang13:06:15

@thheller sorry if I didn't make it clear. I'm not using node-repl or browser-repl, but connecting to shadow-cljs from emacs+cider. and project/lib.js is a file I open in emacs.

// project/lib.js
(ns project.lib)
(defn f1 [])

(comment
  (f1)
)
1. I open the project, and cider-jack-in 2. I can call (f1) in the comment form, which returns nil 3. I put the emacs cursor in the end of the ns form, and cider-eval that form (e.g. I often do that to add new imports to current ns) 4. now if i try to call (f1) again, it throws that error

thheller14:06:12

I do not know emacs and this doesn't tell me anything about what you are actually doing

Lucy Wang15:06:09

I see. Just replace emacs with "cursive/vim". Open a cljs file in cursive/vim, and eval the ns form of that file. Then all the vars for that ns is gone.

thheller17:06:04

please report it as a reprocucible example with ONLY shadow-cljs node-repl or shadow-cljs browser-repl. no editor or other configuration. otherwise I will not investigate this further.

Lucy Wang00:06:20

@thheller Here it is with node-repl (TBH, they are essentially the same as my earlier examples):

$ yarn shadow-cljs node-repl 
cljs.user=> (ns foo.bar)
nil
foo.bar=> (defn f1 [] (println "foo.bar/f1 called!"))
#'foo.bar/f1
foo.bar=> (f1)
foo.bar/f1 called!
nil
foo.bar=> (ns foo.bar)
nil
foo.bar=> (f1)
------ WARNING - :undeclared-var -----------------------------------------------
 Resource: <eval>:1:2
 Use of undeclared Var foo.bar/f1
--------------------------------------------------------------------------------
foo.bar=> (require 'foo.bar)
nil
foo.bar=> (f1)
------ WARNING - :undeclared-var -----------------------------------------------
 Resource: <eval>:1:2
 Use of undeclared Var foo.bar/f1
--------------------------------------------------------------------------------

Lucy Wang01:06:08

version info: mac os 10.15 shadow-cljs version: 22:10:44 js | shadow-cljs - server version: 2.10.12 running

thheller07:06:58

@wxitb2017 please report as a github issue. slack will get lost.

thheller17:06:31

@zilti please post the full error. very hard to piece together what you are actually doing or what is missing.

zilti17:06:11

@thheller that is the full error. (Or rather was, I deleted the node_modules folder now, and ran npx shadow-cljs again, and it installed and ran. I suspect it is a problem that I had shadow-cljs in my package.json file?)

Spaceman20:06:34

how do I run pure js code from cljs? I have a js code snippet that needs to be run on a dom event. What's a simple way to do this?

Spaceman20:06:23

the js code is in the public resources directory file

Spaceman20:06:38

This is the code in the google-maps.js file:

(function(exports) {
                 "use strict";

                 console.log("loading map");
                 function initMap() {
                     exports.map = new google.maps.Map(document.getElementById("map"), {
                         center: {
                             lat: -34.397,
                             lng: 150.644
                         },
                         zoom: 8
                     });
                 }

                 exports.initMap = initMap;
             })((this.window = this.window || {}));

Spaceman20:06:14

I'm using shadow so can I import this file and run it? How exactly? @thheller?

thheller20:06:50

@pshar10 whats the point? why not rewrite it in CLJS?

Spaceman20:06:07

this is not a special case.

Spaceman20:06:41

I have this in google_maps.js:

export function initMap() {
                     exports.map = new google.maps.Map(document.getElementById("map"), {
                         center: {
                             lat: -34.397,
                             lng: 150.644
                         },
                         zoom: 8
                     });
                 }

Spaceman20:06:02

and I imported like this:

["./google_maps.js" :refer (initMap)]

thheller20:06:03

thats not valid JS

Spaceman20:06:05

but it doesn't work

Spaceman20:06:29

why is it not valid?

thheller20:06:39

exports.map =

thheller20:06:52

change that to return

Spaceman20:06:46

still gives initMap is not a function. Is it imported correctly?

Spaceman20:06:02

What is the default directory? the watch directory in shadow edn?

Spaceman20:06:46

or a combination of the watch directory and the asset path>

thheller20:06:42

none of those questions are relevant for what you are doing

thheller20:06:51

the import is correct yes

thheller20:06:02

assuming that the path is correct and it actually compiles correctly

thheller20:06:46

do you get compile errors or does it just fail at runtime?

Spaceman20:06:48

Compilation failed!

The required JS dependency "./google_maps.js" is not available, it was required by 

Spaceman21:06:22

Adding :source-paths ["resources/public/js"] in shadow config didn't work

Spaceman21:06:18

The required JS dependency "./google_maps.js" is not available, it was required by

Spaceman21:06:42

the file is in resources/public/js

thheller21:06:34

that is not the correc solution

thheller21:06:47

move the file into the same folder as the file you are including it from

Spaceman21:06:12

being loaded like so:

(def load-map (with-meta identity
                {:component-did-mount
                 initMap}))

[load-map [:div {:id "map"}]]
gives: initMap is not a function

Spaceman21:06:05

(index):1 Uncaught (in promise) Vc {message: "initMap is not a function", name: "InvalidValueError", stack: "Error↵ at new Vc (https://maps.googleapis.com/m} Promise.then (async) ij @ js?key=AIzaSyD1r7IEvY&callback=initMap&libraries=&v=weekly:136 google.maps.Load @ js?key=AIzaSyD1r7IEvvf6w8FlHu3k_hP_oJwW4_MfQzY&callback=initMap&libraries=&v=weekly:14 (anonymous) @ js?key=AIzaSyD1r7IEvvf6w8FlHu3k_hP_oJwW4_MfQzY&callback=initMap&libraries=&v=weekly:227 (anonymous) @ js?key=AIzaSyD1r7IEvvf6w8FlHu3k_hP_oJwW4_MfQzY&callback=initMap&libraries=&v=weekly:227 This error is after the console.log print console.log("init map"), the first line of initMap

Pavel Klavík21:06:04

Hi, I have rebuild my client with 2.10.12 version and I am getting the following errors on the start:

Pavel Klavík21:06:20

I did some changes in my rf code but it does not seem to be related to this in any way.

thheller21:06:44

I assume there are more errors? all of the errors in that screenshot are likely to something else before that (might be reported after)

Pavel Klavík03:06:14

Ok, so the error was silly. During refactoring, I moved one namespace and forgot to change its path so it was not matching the new location. Refactoring features in Cursive are not perfect. Couldn't this be checked by Shadow-cljs and some error be displayed?

Spaceman21:06:32

@thheller initMap is not a function

Spaceman21:06:07

but the console.log in initMap prints

thheller21:06:10

@pshar10 last warning ... if you continue to be this impatient I will start to ignore youi

thheller21:06:24

I have stuff to do I cannot spend every second trying to help you with your issue

thheller21:06:53

I do not know what is going on in your problem but the issue is that the google maps stuff expects to call an initMap function

thheller21:06:04

which does not exist since it is not on the global namespace

thheller21:06:43

so was under the impression that YOU want to call this function but it looks like google will call that function for you

thheller21:06:51

so the entire setup you are trying is incorrect

thheller21:06:18

I do not know anything about the google maps API so I cannot tell how the correct version would look

Lucy Wang01:06:57

@thheller nope, for a better example, take this ns as an example

// project/lib.js
(ns project.lib)

(defn f1 [])
So this ns has a f1 var. But if I eval the ns form again, and try to catch f1 , it would throw the error I pasted above.

rberger03:06:04

Still having this issue that changes in the JS file does not trigger shadow in watch mode to rebuild. The Browser Console, the shell terminal running shadow-cljs -A:dev watch app, nor the webpage itself show any indication that a rebuild happens. The JS file is not in resources (other than the compiled output). I wasn’t quite sure what was meant in the guide (https://shadow-cljs.github.io/docs/UsersGuide.html#classpath-js) by: > The files must not be physically located in the same directory. The lookup for the file appears on the classpath instead. This is unlike node which expects relative requires to always resolve to physical files. So I tried all the permutations I could think of and none of them would trigger shadow-cljs watch to rebuild. Updating any CLJS file did as normal. Here is what I tried: 1. With the JS file in the same source tree (but not directory) as the cljs file requiring the JS file: deps.edn :path ["src"]

(ns visx.dashboard.antmedia
  (:require
   ["/visx/dashboard/antmedia/webrtc_adaptor.js" :refer [WebRTCAdaptor]]))
or
(ns visx.dashboard.antmedia
  (:require
   ["./antmedia/webrtc_adaptor.js" :refer [WebRTCAdaptor]]))
with the file layout:
├── package.json
├── shadow-cljs.edn
└── src
    └── visx
        └── dashboard
            └── antmedia.cljs
            |__ antmedia
                |__ webrtc_adapter.js
2. Or when the JS file is a different directory tree under src:
(ns visx.dashboard.antmedia
  (:require
   ["/js/dashboard/antmedia/webrtc_adaptor.js" :refer [WebRTCAdaptor]]))
├── package.json
├── shadow-cljs.edn
└── src
    └── visx
        └── dashboard
            └── antmedia.cljs
            |__ antmedia


    └── js
        └── dashboard
            └── antmedia
                |__ webrtc-adapter.js
3. Or when the JS is in a different tree but matching class path with updated :path: deps.edn: :path ["src/js" "src/cljs"]
(ns visx.dashboard.antmedia
  (:require
   ["/visx/dashboard/antmedia/webrtc_adaptor.js" :refer [WebRTCAdaptor]]))
or
(ns visx.dashboard.antmedia
  (:require
   ["./antmedia/webrtc_adaptor.js" :refer [WebRTCAdaptor]]))
├── package.json
├── shadow-cljs.edn
└── src
    [__ cljs
        └── visx
            └── dashboard
                └── antmedia.cljs
                |__ antmedia
    └── js
        |__ visx
            └── dashboard
                └── antmedia
                    |__ webrtc-adapter.js