shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Stuart Campbell 2021-04-07T05:16:48.438800Z

Hello, I just tried adding an NPM package called https://gildas-lormeau.github.io/zip.js/ to my project, and compilation failed with this error about a missing Babel plugin:

SyntaxError: […]/node_modules/@zip.js/zip.js/lib/core/codecs/codec-pool-worker.js: Support for the experimental syntax 'importMeta' isn't currently enabled (82:72):

  80 | 	let messageTask;
  81 | 	if (!workerData.interface) {
> 82 | 		workerData.worker = new Worker(new URL(workerData.scripts[0], import.meta.url));
     | 		                                                                     ^
  83 | 		workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false);
  84 | 		workerData.interface = {
  85 | 			append(data) {

Add @babel/plugin-syntax-import-meta (<https://git.io/vbKK6>) to the 'plugins' section of your Babel config to enable parsing.
I found https://github.com/thheller/shadow-cljs/issues/190 but I wasn’t sure how to proceed. One comment in there suggested that .babelrc could somehow be used, but I’m not sure if that’s applicable here.

thheller 2021-04-07T07:43:42.442100Z

this is not currently supported but the library seems to contain a prepackaed version without the worker via (:require ["@zip.js/zip.js/dist/zip-no-worker.min.js" :as zip]) maybe that works for you

Stuart Campbell 2021-04-07T15:59:53.450600Z

OK cool, that might work – I’ll give it a shot. Thanks!

2021-04-07T05:27:23.440900Z

Are there any consequences from the new npm require syntax for Shadow-cljs? Should we prefer the official statements now?

Karol Wójcik 2021-04-07T07:09:58.441500Z

What are the official statements?

thheller 2021-04-07T07:39:07.441900Z

the $ syntax has been in shadow-cljs for a long time too. it is a useful addition so use it when it make sense for you.

Karol Wójcik 2021-04-07T13:08:39.447200Z

Ahh. That's that new one! 😄 Thanks @thheller 🙂

Karol Wójcik 2021-04-07T07:09:58.441500Z

What are the official statements?

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:39:07.441900Z

the $ syntax has been in shadow-cljs for a long time too. it is a useful addition so use it when it make sense for you.

thheller 2021-04-07T07:43:42.442100Z

this is not currently supported but the library seems to contain a prepackaed version without the worker via (:require ["@zip.js/zip.js/dist/zip-no-worker.min.js" :as zip]) maybe that works for you

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.

2021-04-07T12:40:44.445Z

I'm trying to set up a new project using shadow-cljs version "2.12.1". • compile works fine • watch throws piggieback-related exceptions • Both work completely fine if I revert to version "2.11.23" (happens to be the version I use on another project).

2021-04-07T12:41:38.445200Z

I can provide the specific exceptions if it would help.

thheller 2021-04-07T12:50:05.445800Z

@pmooser most likely you are using project.clj or deps.edn and have not bumped the CLJS version after bumping shadow-cljs

thheller 2021-04-07T12:50:42.446400Z

2.12.0 requires CLJS 1.10.844, which is why it did the 2.11 -> 2.12 bump

2021-04-07T12:52:39.446700Z

Sorry about that. I thought I used that version, but you must be correct.

2021-04-07T12:52:40.446900Z

Thank you.

2021-04-07T12:53:34.447100Z

Yes, that fixes it.

Karol Wójcik 2021-04-07T13:08:39.447200Z

Ahh. That's that new one! 😄 Thanks @thheller 🙂

iGEL 2021-04-07T15:56:56.450400Z

Hey. I'm still on my lein-figwheel -> shadow-cljs adventure 😉 Right now I'm trying to replace the cljsjs/clipboard code with the npm package. I've added the same version (1.6.1) with yarn, and required ["clipboard" :as clipboard]instead of cljsjs.clipboard. But how do I update this line?

(new js/Clipboard (rdom/dom-node button))

Stuart Campbell 2021-04-07T15:59:53.450600Z

OK cool, that might work – I’ll give it a shot. Thanks!

thheller 2021-04-07T16:02:29.451500Z

@igel your are getting rid of the js/GlobalThingy references and just use it like any regular CLJS namespace

thheller 2021-04-07T16:02:42.451900Z

or in this case it is special since you are using it as a regular var

thheller 2021-04-07T16:02:53.452200Z

so just (new clipboard (rdom/dom-node button)). just using the :as clipboard directly

iGEL 2021-04-07T16:05:24.453Z

Thanks, the last suggestion was what I needed. 👍

rkiouak 2021-04-07T16:22:52.453200Z

in my experience, there is definitely no need to manage dependencies in deps or project.clj, just want to echo thhellers comment (I find that managing npm deps in shadow-cljs.edn is FAR less maintenance work than dealing with deps.edn or project.clj finagling I end up doing when working with npm deps in those)

2021-04-07T18:41:12.454100Z

Any idea what the error IllegalStateException: Externs must contain builtin for env BROWSER: whatwg_console.js is caused by? I'm trying to migrate everything to the newest cljs and shadow-cljs.

thheller 2021-04-07T18:44:02.454700Z

some classpath issue probably. maybe you excluded a dependency too much?

thheller 2021-04-07T18:44:49.455100Z

they should be part of the closure-compiler

2021-04-07T18:45:53.455300Z

Hmmm. I'll keep digging, thanks.

thheller 2021-04-07T18:47:36.455600Z

or maybe a good old guava conflict 😛

2021-04-07T18:48:17.456400Z

Yeah, I'm not sure. It doesn't happen with my old compiled artifact, but I happen to be trying pull in a local project (which I am also updating) via :local/root. So it's interesting that if I just use the old thing it's fine.

2021-04-07T18:48:29.456800Z

I've updated that project's deps (of course) ... but the code is all identical.

thheller 2021-04-07T18:49:49.457400Z

could be an issue in in shadow-cljs, cljs, closure-compiler. hard to say without more info.

2021-04-07T18:50:18.458Z

Yeah. I'm going to stop for the day soon. I'll see if I can gather some more useful information in the morning.

thheller 2021-04-07T18:52:39.458700Z

oh, this should be in the closure-compiler-externs artifact I think. maybe you just excluded that by accident

thheller 2021-04-07T18:53:29.459100Z

or maybe you have a externs.zip on the classpath? 😛

thheller 2021-04-07T18:54:03.459600Z

shadow-cljs clj-repl (<http://clojure.java.io/resource|clojure.java.io/resource> "externs.zip") should give a clue

2021-04-07T18:56:09.459900Z

That yields:

"jar:file:/Users/taronish/.m2/repository/com/google/javascript/closure-compiler-externs/v20180805/closure-compiler-externs-v20180805.jar!/externs.zip"

2021-04-07T18:57:18.460300Z

I imagine those are old ...

thheller 2021-04-07T18:57:35.460600Z

that looks too old yes, I get

#object[java.net.URL 0x1a418fc7 "jar:file:/C:/Users/thheller/.m2/repository/com/google/javascript/closure-compiler-unshaded/v20210302/closure-compiler-unshaded-v20210302.jar!/externs.zip"]

2021-04-07T18:57:55.461300Z

I'm wondering why pulling in the local project that way makes it use ancient externs, assuming that is what is happening.

thheller 2021-04-07T18:58:32.462200Z

hmm so I guess that might be the reason. they seem to have combined it into the closure-compiler-unshaded and the separate closure-compiler-externs don't exist anymore?

2021-04-07T18:59:00.462900Z

I'm not personally sure where this comes from ... is there any way to "tell it" to use a newer one?

thheller 2021-04-07T19:00:10.463200Z

clj -Stree should tell you what is adding it

2021-04-07T19:01:20.463600Z

Hmm I wonder if I can just exclude that from wherever it is coming from?

thheller 2021-04-07T19:02:37.463900Z

you can, just :exclusions

2021-04-07T19:05:00.464100Z

That did it. Thank you very much.

thheller 2021-04-07T19:05:39.464500Z

good to know that might be an issue. did the lib have a direct dependency on the externs?

2021-04-07T19:06:51.464900Z

No - not that I can see anyway.

2021-04-07T19:07:13.465200Z

It is coming in because that project is pulling in: org.clojure/clojurescript 1.10.597

thheller 2021-04-07T19:08:28.465800Z

thats like ancient history, 2.12 should definitely be used with 1.10.844

2021-04-07T19:08:55.466100Z

Yes, it makes sense. I will talk to the library author and get him to update.

2021-04-07T19:09:09.466600Z

I'm wondering if this has been responsible for some other weirdness I've seen related to this library.

2021-04-07T19:09:29.467100Z

Thanks for helping me debug it - I would never have traced it back to externs like that.

yiorgos 2021-04-07T19:15:24.470800Z

what is the preferred way to do repl driven dev with shadow-cljs alongside tools.deps? I’ve got the backend using tools.deps and I would like to implement the front end with re-frame, but if I connect with vim/fireplace to the nrepl that shadow starts I can’t eval the backend related code because it cant find the libraries in the class path. Should I use tools.deps for both shadow-frontend/backend tasks?

yiorgos 2021-04-07T19:15:26.471100Z

thanks!

thheller 2021-04-07T19:16:35.471700Z

can fireplace open a second connection to your backend?

yiorgos 2021-04-07T19:16:49.472100Z

I’m not quite sure about that tbh

thheller 2021-04-07T19:17:07.472600Z

me neither but that would be the optimal solution

thheller 2021-04-07T19:17:18.473100Z

otherwise you could run shadow-cljs as part of your backend process, using the embedded mode https://shadow-cljs.github.io/docs/UsersGuide.html#embedded

1👍
yiorgos 2021-04-07T19:17:22.473300Z

is cider capable of doing that?

thheller 2021-04-07T19:17:59.473700Z

cider can do multiple connections I think yeah

yiorgos 2021-04-07T19:18:08.473900Z

👍

dottedmag 2021-04-07T20:49:44.475100Z

Is it expected that throwing an exception in Node.js REPL causes the runtime to exit? E.g.:

% shadow-cljs node-repl
shadow-cljs - config: /Users/dottedmag/w/hz/shadow-cljs.edn
shadow-cljs - server version: 2.12.1 running at <http://localhost:9630>
shadow-cljs - nREPL server started on port 52529
cljs.user=&gt; shadow-cljs - #4 ready!


(throw "x")


^C
The previously used runtime disappeared. Will attempt to pick a new one when available but your state might be gone.
cljs.user=&gt; Failed to read: clojure.lang.ExceptionInfo: Input/output error {:type :reader-exception, :line 2, :column 1, :file "dummy.cljs"}

dottedmag 2021-04-07T20:50:55.476200Z

Also the message about disappeared runtime does not appear until ^C