Fork me on GitHub
#shadow-cljs
<
2020-05-05
>
namenu04:05:14

can I browser-repl without automatically opening a default browser?

namenu04:05:31

ok, i've added this snippet to my user.ns to kill browse-open. 😶

(reset! *open-url-script* "/usr/bin/false")

niwinz06:05:46

Hello, After upgrading from 2.8.93 to the latest one i start getting some warnings:

niwinz06:05:04

shadow-cljs - watching build :main
[:main] Configuring build.
[:main] Compiling ...
------ WARNING #1 -  -----------------------------------------------------------
Resource: simplified-externs.js:2
name ShadowJS is not defined in the externs.
--------------------------------------------------------------------------------
[...]
------ WARNING #5 -  -----------------------------------------------------------
Resource: simplified-externs.js:6
name ShadowJS is not defined in the externs.
--------------------------------------------------------------------------------
[:main] Build completed. (1060 files, 1057 compiled, 0 warnings, 52.05s)

niwinz06:05:49

it compiles successfully but the warning are noisy.

niwinz06:05:13

If I remove the externs directory, the warning disapears.

pmooser08:05:31

I have a couple shadow-cljs questions (again). 1. I'm seeing a CORS preflight error when I try to load my app via the shadow-cljs dev http server. I had an entry in :push-state/headers which I thought would take care of this, but I'm not quite sure what else to do or even how to debug exactly what is going on. 2. If I don't use the shadow-cljs dev http server, and just go directly to my app's server, everything is mostly OK except I see some weird messages in the console when it tries to reload cljs code, where I just see the line: "shadow-cljs: can't find fn" (I have the impression that this normally would have the fn name after it) ...

pmooser08:05:43

If anyone has suggestions for either of those, I'd be very grateful.

thheller08:05:41

1) CORS headers must be set by the server answering the request so if you request data from another server THAT server must set the headers not the :dev-http server.

thheller08:05:47

2) no clue. you just have to load static files, functionality should be identical. only thing I can think of is that some files fail to load? any loading errors in the browser console? maybe some bad caching logic in your server?

pmooser08:05:15

Ok, I will try to double-check that the server is doing the right cors things. It's a little baffling because I can't see an awful lot about it in the browser's record of the request. As far as number 2, no loading errors in the console at all, but I've seen this on a couple projects in the last weeks that I am working on that are similar, and I suspect it is particular to the bootstrap build. Since it's a code-reloading thing, and since I think it won't happen if I am going via the dev http server, it probably isn't that important for me to investigate if I can fix the CORS issue.

pmooser08:05:24

@thheller Thank you for the response!

thheller08:05:29

nothing in the hot-reload process uses either the dev-http or your server

thheller08:05:46

it always talks directly to the shadow-cljs main server regardless of how the files were served

pmooser08:05:08

I'm just telling you the consistently reproduceable facts.

pmooser08:05:12

It may well be my configuration,

pmooser08:05:20

but I'm not doing anything that strange, to be honest.

pmooser08:05:30

(other than doing the cljs-in-cljs eval stuff)

thheller08:05:37

I'd be happy to look at an actual reproducible case 😛

pmooser08:05:02

Yeah that's a reasonable request ... I can't share my actual project but I wonder if I can make a skeleton project with the same characteristics.

thheller08:05:26

shadow-cljs: can't find fn means that the server-side compile found a hook function (eg. :dev/after-load or config) but didn't find it at runtime

thheller08:05:38

it is literally just trying to look it up by name

pmooser08:05:41

Yeah, I only have one of those functions defined.

pmooser08:05:50

I wonder why on earth it thinks it can't find it ...

thheller08:05:03

it doesn't think it .. it can't find it

pmooser08:05:19

It may be that it's another path problem somehow (since I'm accessing it via a different URL I guess) ... but I don't see any loading errors at all ... ?

thheller08:05:29

I mean go into the browser console and type in the name of the function it is supposed to call

thheller08:05:34

its either there or it isn't

pmooser08:05:31

I mean it's a function, if I just type foo.bar.fn-name

pmooser08:05:33

in the js console

thheller08:05:48

the munged name yes, so that would be foo.bar.fn_name

pmooser08:05:23

But the question also is, why is the fn-name blank in the log msg?

pmooser08:05:30

(doesn't it try to log the fn symbol?)

thheller08:05:41

its kind easy to destroy the runtime state with self-hosted code if you are not careful

pmooser08:05:53

Yes, so sorry, I think the munged name is completely present in the js console if I type it.

thheller08:05:01

so maybe you are loading code you shouldn't be loading via self-host? like loading a different cljs.core instance?

pmooser08:05:09

What code should I not be loading I wonder?

thheller08:05:02

those should ensure that it doesn't load files that are already loaded

pmooser08:05:08

I will review ... one moment please.

pmooser08:05:41

I am using init ... I don't think I am using load ...

thheller08:05:00

you can also review the websocket messages via the browser console, see if the message actually contains an emtpy fn call (which shouldn't be possible in theory as it would be invalid transit)

pmooser08:05:09

Sorry, I was wrong.

pmooser08:05:17

I am using both init and load, very similar to what is shown in that blog post.

pmooser08:05:27

My init callback doesn't do anything though.

pmooser08:05:36

But when I use eval, I use boot/load every time.

pmooser08:05:54

Yeah, I tried looking at the WS calls in the browser, but I didn't see an error,

pmooser08:05:58

but maybe I can look closer.

thheller08:05:08

its not an error. its a regular :build-complete message

thheller08:05:17

that contains all the info about what it should be reloading and so on

pmooser08:05:54

So I am guessing the problem is related to this:

pmooser08:05:58

:before-load [{:fn-sym nil, :fn-str ""} {:fn-sym nil, :fn-str "", :async true}]

thheller08:05:30

no clue how that happens though? especially since that is always done by the shadow-cljs main server and not related to the dev-http at all

pmooser08:05:53

Yes, I mean I'm sure you must be correct that it is something in my config I am doing wrong

pmooser08:05:08

I am having a hard time even pprinting that stuff in emacs, it's too slow

pmooser08:05:20

I just need to learn enough about shadow-cljs internals to be able to effectively debug it

thheller08:05:22

oh one idea. do you use shadow-cljs in any kind of embedded way?

thheller08:05:47

you calling server/start! embedded in another CLJ process?

thheller09:05:11

honestly not sure how it would ever get a nil there

pmooser09:05:13

Nope, I don't think so, I mean I am launching shadow-cljs with clj , but I'm not manually managing it or starting servers or anything.

thheller09:05:41

which version do you use?

pmooser09:05:04

thheller/shadow-cljs {:mvn/version "2.8.83"}

thheller09:05:10

and kind of :build-hooks or something else that may be touching the compiler state?

pmooser09:05:15

No build-hooks

pmooser09:05:20

If I wanted to set a breakpoint in that code you showed me, is there an easy way to do that?

pmooser09:05:28

I'm not really sure how to run shadow-cljs under a debugger.

thheller09:05:53

do you use intellij?

pmooser09:05:42

Nope. Just emacs.

pmooser09:05:48

I could install IntelliJ I think.

thheller09:05:51

then I can't tell you 😛

pmooser09:05:56

(if that would be much easier)

pmooser09:05:06

For now I am trying to dig around in browser's debugger

pmooser09:05:12

but that probably won't be too illuminating

thheller09:05:47

the problem is on the server if you get weird empty hooks like that

thheller09:05:55

nothing the client does affects that in any way

pmooser09:05:48

Yeah, I suspected as much.

pmooser09:05:08

Well, thank you very much for your help. I will see what I can do to dig a little more, and then I will try to ask some more useful questions.

pmooser09:05:54

I'm guessing it's all some combination of different paths I'm using or something along those lines.

pmooser09:05:10

My colleagues use IntelliJ

pmooser09:05:23

I might ask them to help out, if I don't install it myself.

thheller09:05:49

you can run things via deps.edn with a debugger attached

pmooser09:05:55

Yeah, I imagine I just need to pass the right jvm args so it will listen on a debug port or whatever

thheller09:05:50

yep, intellij will do that for you. no clue about emacs debugging support.

pmooser09:05:07

Yeah, to be honest, me neither. I have used it before but not often.

niwinz09:05:10

@thheller do you know what can be the cause of the

------ WARNING #5 -  -----------------------------------------------------------
Resource: simplified-externs.js:6
name ShadowJS is not defined in the externs.
--------------------------------------------------------------------------------

niwinz09:05:10

i start seeing this warning on update from 2.8.93 to the latest version of shadow-cljs (as a side note, if i remove externs/ directory the warning disapears).

thheller09:05:53

not sure. I haven't touched any of the externs related code so it might be the new closure-compiler version having changed something

thheller09:05:18

the simplified-externs.js is generated by the externs/build.txt so yeah removing that removes the file

thheller09:05:35

but it should generate the proper output

niwinz09:05:38

yeah but 2.8.93 don't shows the warning with the same cljs version

thheller09:05:00

closure-compiler version

thheller09:05:04

CLJS isn't related to any of this

niwinz09:05:32

hmm but closure-compiler version is updated with cljs or with shadow-cljs?

thheller09:05:33

but you can't use the current closure-compiler version with the old CLJS version

thheller09:05:23

if you do it correctly with shadow-cljs. if you use project.clj it depends. if you use deps.edn it should be picking the newest available version (which shadow-cljs depends on)

niwinz09:05:19

i'm using deps.edn

thheller09:05:32

ok then check which versions you are getting

niwinz09:05:46

com.google.javascript/closure-compiler-unshaded v20200406

thheller09:05:06

yeah thats the version shadow-cljs depends on

thheller09:05:29

you can downgrade that to test if you want

niwinz09:05:45

i go to investigate what is the cause, thanks!

thheller09:05:47

just declare it directly as a dep

thheller09:05:32

v20191027 would be the version used in 2.8.93. it should still work.

niwinz09:05:17

thanks, i will do it as workaround.

thheller09:05:37

whats the problem though? just a couple warnings or does it actually affect anything?

thheller09:05:57

I mean I have an idea why it might be happening

thheller09:05:15

but not sure why it suddenly became a problem when it has worked for the past year or so

niwinz09:05:01

yeah, is just a warning, and i just wanted let you know about this, that it start happening suddenly

thheller11:05:45

@niwinz did you try the older closure-compiler version? if so, does it make the warnings to away?

niwinz11:05:18

@thheller yes, just tried right now, and no, latest version of shadow-cljs and com.google.javascript/closure-compiler-unshaded {:mvn/version "v20191027"}

niwinz11:05:29

and the warning still appears :S

niwinz11:05:13

uxbox@uxbox-devenv-main:~/uxbox/frontend/ > clj -Adev -Stree |grep closure
org.clojure/google-closure-library 0.0-20191016-6ae1f72f
org.clojure/google-closure-library-third-party 0.0-20191016-6ae1f72f
com.google.javascript/closure-compiler-unshaded v20191027
com.google.javascript/closure-compiler-externs v20191027
uxbox@uxbox-devenv-main:~/uxbox/frontend/ > clj -Adev -Stree |grep shadow
thheller/shadow-cljs 2.8.110
thheller/shadow-cljsjs 0.0.21
thheller/shadow-util 0.7.0
thheller/shadow-client 1.3.2

thheller11:05:43

looks fine. youj can open a github issue if you want. don't have time to look into this further now. really shouldn't warn about internal things so I'd like to fix that.

niwinz11:05:45

i'll open an issue, sure. I have an other one related to fingerprint-hash, modules and webworker (where web worker tries to import "shared.js" when the fingerprint-hash is activated and the shared.js is renamed to shared.<md5hash>.js file)

niwinz11:05:10

but the last one i need to recheck it with the latest version before report

schaueho13:05:06

I just started using shadow-cljs and I keep running into an issue on re-compilation. I get the following error which I couldn't find any reference to with my search-engine-fu: ExecutionException: clojure.lang.ExceptionInfo: failed to publish!, offer! failed {:msg {:type :build-log, :build-id :test, :event {:type :flush-source, :resource-name "node_modules/@material-ui/icons/CalendarViewDayTwoTone.js", :timing :exit, :timing-id 1489, :depth 1, :stop 1588684288351, :duration 3, :shadow.build.log/level :info}}, :topic :shadow.cljs.model/build-log}

schaueho13:05:55

This doesn't come up after removing the output-dir contents on a first compile / watch.

thheller15:05:22

@schaueho thats odd. its a backpressure thing where its trying to log faster than the log consumer can read it. never heard of anyone else running into this before

schaueho07:05:52

My machine is pretty powerful (Ryzen Threadripper), maybe that's part of the reason. I can log an issue, if you want me to.

thheller07:05:35

I fixed the issue in master yesterday (I think). should be good with the next release.

schaueho07:05:05

Great. Thanks!

thheller15:05:42

I guess I can turn this into a warning instead since its not really critical to drop that message

thheller15:05:09

guess it just gets overloaded by when trying to flush the thousands of files @materiel-ui has

JaimeV19:05:40

@thheller any news about shado-arborist?

thheller19:05:35

@jev I'm using it for the shadow-cljs UI but no news beyond that. still lots of stuff to figure out and not much time to work on it.

fabrao21:05:40

hello all, how do I use something like this in cljs var Connection = require('../lib/tedious').Connection; ?

fabrao21:05:35

I tried with

(ns app.core
  (:require
   ["express" :as express]
   ["tedious" :as sql]))

(defn create-connection []
    (sql/Connection. {}))
but no Connection found

thheller21:05:06

don't know that library sorry. you can try running node and then require("tedious")

thheller21:05:29

I'm assuming you are running a node build because of the express? ie. now a :target :browser build?

fabrao21:05:51

Yes, I´m trying to use with node and with express

thheller21:05:58

and if you run the node thing do you get something that has a Connection object?

fabrao21:05:48

error when calling lifecycle function app.core/start! TypeError: Cannot read property 'Connection' of undefined

thheller21:05:54

do the plain node please

thheller22:05:13

I want to first confirm that it actually works in node. that is the only test you have to do.

fabrao22:05:43

ho, you mean testing in javascript node?

thheller22:05:13

literally just go into your project directory and run node in a terminal

thheller22:05:05

and then run require("tedious") or require("tedious").Connection

fabrao22:05:52

require("tedious")
{
  connect: [Function: connect],
  BulkLoad: [Getter],
  Connection: [Getter],
  Request: [Getter],
  ConnectionError: [Getter],
  RequestError: [Getter],
  TYPES: [Getter],
  ISOLATION_LEVEL: [Getter],
  TDS_VERSION: [Getter],
  library: { name: 'Tedious' }
}
> require("tedious").Connection
[Function: Connection]

thheller22:05:14

ok that looks fine

thheller22:05:22

whats your build config?

fabrao22:05:45

{:source-paths
 ["src"]

 :dependencies
 []

 :builds
 {:app
  {:main app.core/main
   :target :node-script
   :output-to "app.js"
   :devtools
   {:after-load app.core/start!
    :before-load app.core/stop!}}}}

fabrao22:05:56

{
  "devDependencies": {
    "shadow-cljs": "^2.8.110"
  },
  "dependencies": {
    "express": "^4.17.1",
    "tedious": "^8.3.0"
  }
}

thheller22:05:30

that looks fine too

thheller22:05:51

try shadow-cljs node-repl and then (require '["tedious" :as x]) and then (js/console.log x)

fabrao22:05:21

cljs.user=>

  Connection: [Getter],

  Request: [Getter],
  ConnectionError: [Getter],
  RequestError: [Getter],
  TYPES: [Getter],
  ISOLATION_LEVEL: [Getter],
  TDS_VERSION: [Getter],
  library: { name: 'Tedious' }
}
nil

fabrao22:05:33

I started it with npx shadow-cljs watch app

fabrao22:05:58

and than node app.js

thheller22:05:02

that all looks fine

thheller22:05:20

but the error you posted suggests it happens on hot-reload?

thheller22:05:30

so it works fine on startup?

fabrao22:05:00

I inserted it after run it up

fabrao22:05:17

yes, after hot-reload

fabrao22:05:41

I think it´s ok now after restarting it

fabrao22:05:48

thanks !!!

JaimeV21:05:01

@thheller Thanks for the update. Is there anyway to help with arborist?

thheller21:05:32

not really. it is just one experiment after another currently. it works well enough but not something I would recommend building on.

JaimeV22:05:58

Ok. I understand. The concept is spot on and would like to see it flourish. I may shadow-cljs UI and do some experiments of my own. I may reach out if I have something to share.