shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
thheller 2021-04-06T06:48:28.380400Z

I have never used bazel but I know someone did. Just forgot who or how

pez 2021-04-06T08:59:59.381400Z

I can’t specify nrepl port via user config, right?

thheller 2021-04-06T09:02:01.381800Z

you should never ever specify a fixed port for nrepl

thheller 2021-04-06T09:02:23.382400Z

let it use a random port and read it from .shadow-cljs/nrepl.port in the project

thheller 2021-04-06T09:02:58.383Z

if by user config you mean ~/.shadow-cljs/config.edn then no since that would start to conflict as soon as you run more than one shadow-cljs instance at the same time

pez 2021-04-06T09:07:41.384500Z

The issue arose because the only Cursive wielding user in our project wanted to add a fixed port. But you are a Cursive user too, aren’t you, @thheller?

thheller 2021-04-06T09:08:35.384900Z

I am and Cursive is perfectly capable of using that file. Absolutely no use for a fixed port in Cursive

pez 2021-04-06T09:08:46.385100Z

Awesome.

thheller 2021-04-06T09:09:50.385200Z

🎉 1
pez 2021-04-06T09:10:45.385600Z

Thanks!

wombawomba 2021-04-06T11:09:22.388900Z

I'm running shadow-cljs watch, and am accessing my frontend via nginx -> my backend service (which serves up my index.html). My browser connects to shadow-cljs just fine, and code reloading works. However, CSS reloading isn't happening. Is there a reason for this, or could it be a bug? Is there a fix? Actually, scratch that. I restarted everything and now it works 🙂

Azzurite 2021-04-06T13:02:32.389300Z

didn't even need the "specify custom file" there, but yeah 😄

bartuka 2021-04-06T14:42:47.390800Z

hello, I am using bide (https://github.com/funcool/bide) to routing and this library makes a call to goog.isDefAndNotNull function. However, I got an error like this:

Execution error (TypeError) at (<cljs repl>:1).
goog.isDefAndNotNull is not a function
there is any additional config I need to setup to make this work on shadow-cljs side?

thheller 2021-04-06T14:59:13.393500Z

@iagwanderson that function was removed in the newer closure-library. bide will need to change that.

thheller 2021-04-06T15:00:41.394600Z

In my project I do because I also use lein and don't want it to get confused. Otherwise the other option also works yes.

thheller 2021-04-06T15:04:01.396400Z

or downgrade shadow-cljs to 2.11.26. 2.12.0 was the released with the new closure-library version

iGEL 2021-04-06T15:07:04.397Z

Hello. I'm trying to migrate some builds from lein-figwheel to shadow-cljs and fail at it :face_palm: Shadow-cljs doesn't find my namespace: The required namespace "data-request.core" is not available. I've slimed down my src/cljs/data_request/core.cljs to this:

(ns data-request.core)

(defn ^:export initialize [x]
  (prn x))
And my shadow-cljs.edn looks like this:
{:source-paths ["src/cljs/data_request"]
 :dependencies []
 :builds {:data-request {:target :browser
                         :modules {:main {:entries [data-request.core]}}
                         :output-dir "../output/dev/"
                         :asset-path "/cljs/output/dev/data-request_target"}}}
But still:
# yarn shadow-cljs watch data-request

yarn run v1.22.10
$ /webapp/cljs/admin/node_modules/.bin/shadow-cljs watch data-request
shadow-cljs - config: /webapp/cljs/admin/shadow-cljs.edn
shadow-cljs - updating dependencies
shadow-cljs - dependencies updated
shadow-cljs - server version: 2.12.1 running at <http://localhost:3450>
shadow-cljs - nREPL server started on port 7890
shadow-cljs - watching build :data-request
[:data-request] Configuring build.
[:data-request] Compiling ...
[:data-request] Build failure:
The required namespace "data-request.core" is not available.

dpsutton 2021-04-06T15:08:56.398400Z

the ns data-request.core would be expected to be at &lt;classpath-root&gt;/data_request/core.cljs. Since your classpath root is src/cljs/data_request, it will be looking for src/cljs/data_request/data_request/core.cljs and not finding it

iGEL 2021-04-06T15:10:21.398800Z

Doh 😉 I was pretty sure I tried that. Thanks 🙂

thheller 2021-04-06T15:12:41.399900Z

The :asset-path also looks incorrect. that should be the path under which you access the files over HTTP, that likely isn't <http://localhost>:port/cljs/output/dev/data-request_target/main.js?

iGEL 2021-04-06T15:16:04.401600Z

With figwheel, we were serving this through Rails and a middleware there was hooking things up. Is that still a good approach for shadow-cljs?

thheller 2021-04-06T15:21:19.402200Z

if it makes sense for you yes. they are still just plain static javascript files, no difference on that front

thheller 2021-04-06T15:22:31.403400Z

the code just needs to be able to connect back to the http://localhost:3450 server. dunno why you reconfigured that from the default 9630. the is only the webserver used for the UI and websockets. It does nothing regarding your other code.

thheller 2021-04-06T15:23:28.404300Z

also you want to avoid using a fixed :nrepl {:port ...} if you can. most editors nowadays support reading that port rom the generated .shadow-cljs/nrepl.port file instead

bartuka 2021-04-06T15:34:38.405800Z

thanks @thheller!

emier 2021-04-06T15:43:45.410Z

Hello! Trying to config the test runner, but running into some problems regarding namespace when trying to compile. Here’s the configs: project.clj

:test
{:dependencies [[binaryage/devtools "1.0.2"]]
 :source-paths ["env/test" "test/src"]}
shadow-clj.edn
:lein {:profile "+dev,+test"}
…
:builds
{:dev {...}
:test 
  {:target     :node-test
   :output-to    "test/target/testable.js"
   :ns-regexp    "myapp\\..*"
   :autorun    true}}
And here’s the problem:
$ npx shadow-cljs watch test
…
[:test] Compiling ...
[:test] Build failure:
Resource does not have expected namespace
{:tag :shadow.build.resolve/unexpected-ns, :resource "src/myapp/runner.cljs", :expected-ns src.myapp.runner, :actual-ns myapp.runner}
Any ideas why it doesn’t accept the namespaces? It hasn’t been a problem with our previous test runner. A potentially relevant side note is that Cursive also complains in these files that the namespace is missing a src. (for example in (ns myapp.test.db ...) ) but it seems to me this shouldn’t be needed.

thheller 2021-04-06T15:56:00.411400Z

@emil.eriksson41 what are the :source-paths you have configured in project.clj? you do not need a "runner" for the tests, that is generated for you by the :node-test target.

emier 2021-04-07T07:20:11.441700Z

Source paths are ["env/test" "test/src"] - some environment configuration variables, and then all the test files. File hierarchy is e.g. test/src/myapp/test/db.cljs You’re right, the runner file remained from old solution. After removing it, same problem remains but for other files (e.g :expected-ns src.myapp.test.api.transform, :actual-ns myapp.test.api.transform)

thheller 2021-04-07T07:50:17.442300Z

it looks like you have "test" on the classpath, which is the default when using lein via :test-paths ["test"]. You need to override that so the classpath doesn't contain duplicated entries.

thheller 2021-04-07T07:51:42.442500Z

but which shadow-cljs version is this with? either you are using a very old shadow-cljs version or something else is going on?

emier 2021-04-07T08:46:42.442700Z

Using 2.11.18 right now. Looks like we didn’t have a :test-paths set in project.clj at all, so I tried setting it to ["test/src"] which seems to have solved the namespace issue! Now I get another error instead but it seems related to our own code.

bartuka 2021-04-06T16:11:59.411600Z

for those interested, this is the commit from closure-library https://github.com/google/closure-library/commit/9325ce1bbebcfe8c7aa54f8342959c73a1762a77

thheller 2021-04-06T16:16:05.411800Z

yeah they removed basically all the <http://goog.is|goog.is>* functions over the past few years. we were stuck with a quite old closure-library version for a while due to those incompatibilities even in cljs.core. the new CLJS release (announcement still upcoming) fixed those but a lot of libraries still need adjustments for the newer version as well

🚀 1
Rob Knight 2021-04-06T16:23:28.412700Z

It seems that the most recent Closure Compiler has removed the stripTypePrefixes compiler option 😞

thheller 2021-04-06T16:24:19.413200Z

they did indeed. it was always the absolute nuclear option anyways though 🙂

Rob Knight 2021-04-06T16:24:48.413600Z

Yeah, now I need to figure out exactly what is adding 94kb of cljs.analyzer to my release build

thheller 2021-04-06T16:26:38.413900Z

https://github.com/thheller/shadow-cljs/issues/865 😉

thheller 2021-04-06T16:26:58.414400Z

there used to be a function for that but it broke a while back. really need to bring that back

Rob Knight 2021-04-06T16:27:53.415400Z

Ah, but that would take all of the fun out of it 😄

Rob Knight 2021-04-06T16:39:12.415900Z

Is that kind of information available anywhere, even if it's hard to get at? I don't mind hacking around

thheller 2021-04-06T16:43:44.416900Z

not in an easily accessible way no. really low level would be in the build-state from a build hook

thheller 2021-04-06T16:45:08.417700Z

from the CLJ REPL (eg. shadow-cljs clj-repl) you can call (def build-state (shadow/compile! :the-build))

thheller 2021-04-06T16:45:28.418200Z

you use (tap&gt; build-state) and look at entire state in the shadow-cljs UI

thheller 2021-04-06T16:45:41.418600Z

do not try to print it from the REPL, it is way too large and will take forever 😉

thheller 2021-04-06T16:46:06.419Z

there is a :compiler-env key and that has :cljs.analyzer/namespaces

thheller 2021-04-06T16:46:24.419500Z

if you really want to dig in that is the place to do it 😛

Rob Knight 2021-04-06T16:47:05.419700Z

Thanks 🙂

awb99 2021-04-06T16:52:47.422700Z

I have https://www.npmjs.com/package/@ricokahler/oauth2-popup-flow in deps.cljs in a library. oauth2-popup-flow has a few dev dependencies like typescript that are needed to compile it. It seems dev dependencies are somehow lost. So I had to add all transient dev dependencies of oauth2-popup-flow to my deps.cljs. Is this intended behavior?

thheller 2021-04-06T16:54:31.423400Z

npm packages generally contain the already compiled code and dev dependencies are used for THEIR development

thheller 2021-04-06T16:55:02.424100Z

they will generally not be used when you use the library so you adding those dependencies to deps.cljs seems like something you should absolutely not do. shadow-cljs will also never compile typescript for you so they'll like remain unused.

thheller 2021-04-06T16:55:31.424400Z

so yes, that is intended

Rob Knight 2021-04-06T17:07:16.424800Z

Is there a way of getting this information for a release build? My problem is that there is various spec-related stuff that I want in my dev builds, but not in my release builds.

awb99 2021-04-06T17:13:01.425200Z

Thanks @thheller

awb99 2021-04-06T17:14:14.426800Z

I have seen a lot of npm libraries that build themselves on npm-install. I dont quite understand why it works in the library, but not via deps.cljs. I will have to investigate more.

Neil Ashton 2021-04-06T17:48:36.432300Z

Hey all! I’m having some issues with shadow-cljs’s build of a web worker. Within that web worker, I’m getting ReferenceError: window is not defined errors; it looks like it’s happening when this line runs, https://github.com/thheller/shadow-cljs/blob/3e559b8f9ea80cc1ad1c51772fe4aa8c099a1159/src/main/shadow/js.js#L82, as a result of my “shared” module calling SHADOW_ENV.evalLoad("cljsjs.jquery.js", …) because of another library’s jQuery dependency (namely castra.core’s). Has anyone else solved this problem in a project?

Neil Ashton 2021-04-06T17:49:16.432500Z

Also, FWIW, I notice that when I explicitly define window at the top of the web worker’s compiled JS by adding var window = goog.global;, that problem goes away – but then I start to get a document is not defined error that seems to ultimately be caused by shadow.dom.js.

thheller 2021-04-06T19:17:01.432800Z

I have not seen a single npm library do that? well maybe those with native dependencies but certainly not typescript

thheller 2021-04-06T19:17:44.433Z

the library you asked about also seems to contain the compiled JS code as expected? https://unpkg.com/@ricokahler/oauth2-popup-flow@2.0.0-alpha.1/index.js

thheller 2021-04-06T19:18:21.433500Z

it also doesn't contain any of the actual .ts code so it couldn't even compile itself?

thheller 2021-04-06T19:18:51.433700Z

never ever look at the git repo when looking at npm libraries. those never reflect how the library is actually distributed.

thheller 2021-04-06T19:19:27.433900Z

when building a web-worker it is your code (or depdencies of that) that must not load references using window

thheller 2021-04-06T19:19:52.434100Z

you also must configure the :module you are using as a web-worker via :web-worker true?

thheller 2021-04-06T19:22:04.434600Z

there is a release! but just noticed that has a bad return value

thheller 2021-04-06T19:22:19.434800Z

but (shadow/release* (shadow/get-build-config :the-build) {}) should be ok

Rob Knight 2021-04-06T19:48:00.435100Z

Thanks

thheller 2021-04-06T19:51:50.435300Z

FWIW the goal should be to get the jquery out of the code loaded by the worker. you might do so by introducing an extra module somewhere in your graph.

Neil Ashton 2021-04-06T20:14:51.435500Z

Yes, looks like that did it. Instead of having all modules depend directly on :shared, I inserted another module between :shared and those modules with jQuery dependencies. No more window-related errors. Thank you!

👍 1
awb99 2021-04-06T20:53:22.435800Z

thanks a lot!