Fork me on GitHub
#shadow-cljs
<
2023-06-21
>
Stefan07:06:35

Hi! After updating shadow-cljs this morning (from 2.23.5 to 2.23.8), I get a client-side Javascript error "_interopRequireDefault is not a function". Is this a bug or am I doing something wrong?

thheller07:06:54

could be a side effect of you now getting different code due to the "exports" support I added

thheller07:06:51

That appears to be more breaking than I hoped for

thheller07:06:07

you can revert back to the old behavior by setting :js-options {:ignore-exports true} for now

thheller07:06:49

can you say which dependency is causing that? need some more libs to test against I guess

Stefan08:06:30

I suspect react-bootstrap but I'll post a stacktrace in a moment.

Stefan08:06:09

(FYI: adding that option indeed fixes the issue for me)

thheller08:06:04

if you feel like it you can try 2.24.0 without that setting, maybe that also works

thheller08:06:43

changed the defaults to be more conservative, might also make :ignore-exports true the default if more problems come up

Stefan08:06:13

I just tried, 2.24.0 seems to work again without the option. Thanks! 🙂

thheller08:06:04

good to know. thanks.

rolt11:06:45

I had a similar issue with highlight.js going from 2.23.5 to 2.23.6: require "./lib/languages/clojure" for package "XXX/node_modules/highlight.js" not exported which was solved by adding :ignore-exports (bumping to 2.24.0 didn't solve it)

Akiz18:11:22

@U05224H0W Hi, i have got the mentioned problem with 2.26.0, I just upgraded from 2.21.0

[:app] Compiling ...
[:app] Build failure:
package @headlessui/react had exports, but could not resolve ./dist/components/dialog/dialog
{:package #object[java.io.File 0x4ca96c7e "/Users/akiz/Projects/BIM/backend-api/node_modules/@headlessui/react"], :require-from nil, :rel-require "./dist/components/dialog/dialog"}
ExceptionInfo: package @headlessui/react had exports, but could not resolve ./dist/components/dialog/dialog
	shadow.build.npm/find-resource-in-package (npm.clj:807)
	shadow.build.npm/find-resource-in-package (npm.clj:793)
	shadow.build.npm/find-resource (npm.clj:923)
	shadow.build.npm/find-resource (npm.clj:847)
	shadow.build.resolve/find-npm-resource (resolve.clj:123)
	shadow.build.resolve/find-npm-resource (resolve.clj:94)
	shadow.build.resolve/eval12174/fn--12177 (resolve.clj:266)
	clojure.lang.MultiFn.invoke (MultiFn.java:244)
	shadow.build.resolve/find-resource-for-string (resolve.clj:81)
	shadow.build.resolve/find-resource-for-string (resolve.clj:70)
	shadow.build.resolve/resolve-string-require (resolve.clj:464)
	shadow.build.resolve/resolve-string-require (resolve.clj:447)
	shadow.build.resolve/resolve-require (resolve.clj:679)
	shadow.build.resolve/resolve-require (resolve.clj:672)
	shadow.build.resolve/resolve-deps/fn--12123 (resolve.clj:52)
	clojure.lang.PersistentVector.reduce (PersistentVector.java:343)
	clojure.core/reduce (core.clj:6885)
	clojure.core/reduce (core.clj:6868)
	shadow.cljs.util/reduce-> (util.clj:42)
	shadow.cljs.util/reduce-> (util.clj:41)
	shadow.build.resolve/resolve-deps (resolve.clj:50)
	shadow.build.resolve/resolve-deps (resolve.clj:34)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:666)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:626)
	shadow.build.resolve/resolve-require (resolve.clj:676)
	shadow.build.resolve/resolve-require (resolve.clj:672)
	shadow.build.resolve/resolve-deps/fn--12123 (resolve.clj:52)
	clojure.lang.PersistentVector.reduce (PersistentVector.java:343)
	clojure.core/reduce (core.clj:6885)
	clojure.core/reduce (core.clj:6868)
	shadow.cljs.util/reduce-> (util.clj:42)
	shadow.cljs.util/reduce-> (util.clj:41)
	shadow.build.resolve/resolve-deps (resolve.clj:50)
	shadow.build.resolve/resolve-deps (resolve.clj:34)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:666)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:626)
	shadow.build.resolve/resolve-require (resolve.clj:676)
	shadow.build.resolve/resolve-require (resolve.clj:672)
	shadow.build.resolve/resolve-deps/fn--12123 (resolve.clj:52)
	clojure.lang.PersistentVector.reduce (PersistentVector.java:343)
	clojure.core/reduce (core.clj:6885)
	clojure.core/reduce (core.clj:6868)
	shadow.cljs.util/reduce-> (util.clj:42)
	shadow.cljs.util/reduce-> (util.clj:41)
	shadow.build.resolve/resolve-deps (resolve.clj:50)
	shadow.build.resolve/resolve-deps (resolve.clj:34)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:666)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:626)
	shadow.build.resolve/resolve-require (resolve.clj:676)
	shadow.build.resolve/resolve-require (resolve.clj:672)
	shadow.build.resolve/resolve-deps/fn--12123 (resolve.clj:52)
	clojure.lang.PersistentVector.reduce (PersistentVector.java:343)
	clojure.core/reduce (core.clj:6885)
	clojure.core/reduce (core.clj:6868)
	shadow.cljs.util/reduce-> (util.clj:42)
	shadow.cljs.util/reduce-> (util.clj:41)
	shadow.build.resolve/resolve-deps (resolve.clj:50)
	shadow.build.resolve/resolve-deps (resolve.clj:34)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:666)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:626)
	shadow.build.resolve/resolve-require (resolve.clj:676)
	shadow.build.resolve/resolve-require (resolve.clj:672)
	shadow.build.resolve/resolve-deps/fn--12123 (resolve.clj:52)
	clojure.lang.PersistentVector.reduce (PersistentVector.java:343)
	clojure.core/reduce (core.clj:6885)
	clojure.core/reduce (core.clj:6868)
	shadow.cljs.util/reduce-> (util.clj:42)
	shadow.cljs.util/reduce-> (util.clj:41)
	shadow.build.resolve/resolve-deps (resolve.clj:50)
	shadow.build.resolve/resolve-deps (resolve.clj:34)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:666)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:626)
	shadow.build.resolve/resolve-require (resolve.clj:676)
	shadow.build.resolve/resolve-require (resolve.clj:672)
	shadow.build.resolve/resolve-entry (resolve.clj:686)
	shadow.build.resolve/resolve-entry (resolve.clj:685)
	clojure.lang.PersistentVector.reduce (PersistentVector.java:343)
	clojure.core/reduce (core.clj:6885)
	clojure.core/reduce (core.clj:6868)
	shadow.cljs.util/reduce-> (util.clj:42)

Akiz18:11:51

And I was able to solve it with :ignore-exports true

thheller20:11:19

exports is a way for npm packages to restrict which files you are allowed to directly required. I'm guessing the package maintainers don't want you to access this directly.

Akiz20:11:02

@U05224H0W this is from the official documentation. import { Dialog } from '@headlessui/react'

thheller20:11:44

yes, thats fine

Akiz20:11:30

Got it. I guess a lot of things have changed in the new versions, thanks :-)

thheller20:11:24

you mean shadow-cljs? the only thing that changed is the added support for exports. previously it was just ignored. to be clear, what it doesn't like is you doing (:require ["@headlessui/react/dist/components/dialog/dialog" :as Dialog]), when they want you to do (:require ["@headlessui/react" :refer (Dialog)])

👍 1
thheller20:11:12

but there are benefits to your style, so I think :ignore-exports is the correct way to go

thheller20:11:14

exports is still relatively new and many packages are pretty strict in what they export. note that this is entirely on the side of the npm package itself, not shadow-cljs. shadow-cljs is just following the rules for exports.

👍 1
Akiz20:11:14

I got another bug when i upgraded https://clojurians-log.clojureverse.org/reagent/2023-03-09 But it was a quick fix. So i guessed there were more changes ;)

Akiz20:11:10

And thank you again!

alexdavis10:06:28

perhaps this is the wrong channel for this question, but is there a way to connect a repl to a web worker context? I've setup a web worker like https://shadow-cljs.github.io/docs/UsersGuide.html#_web_workers and it all works, but I can't figure out how to evaluate code in the worker process

thheller10:06:16

under http://localhost:9630/runtimes you can see the connected runtimes

thheller10:06:54

there should be one browser-worker showing up in addition to the regular browser one

thheller10:06:39

when connected to the normal CLJ nrepl you may select the worker via (shadow/repl :app {:runtime-id <id-of-worker>})

👍 1
thheller10:06:49

shadow alias being shadow.cljs.devtools.api

thheller10:06:12

it is a bit manual since no editor unfortunately provides any kind of mechanism to select this

thheller10:06:12

:cljs/quit drops you down back to the CLJ repl, so you can switch back and forth. or just open a second connection of stay connected to both

thheller10:06:34

the id of the runtime is also logged in the browser console, but you'll see both

alexdavis11:06:25

Thanks! got it all working, a bit of hassle compared to the normal way but I guess like you said thats on cider/conjure/etc

Rachel Westmacott11:06:23

Is there documentation for https://clojureverse.org/t/using-none-code-resources-in-cljs-builds/3745 beyond that page? Perhaps there's nothing else I need to know about it.

thheller11:06:12

there is not really anything else to know about it, reads a resource and inlines it

👍 1
thheller11:06:21

anything in particular you want to know?

Rachel Westmacott13:06:44

I guess it just seems unusual to reach out to a build tool from within project source code.

thheller13:06:15

consider that code a library where I'm just to lazy to make it an actual separate library 😛

Rachel Westmacott14:06:05

I find it hard to consider you too lazy! gratitude

😄 2
Casey14:10:14

An argument for mentioning this in the user guide: When I'm trying to figure out how to do something with shadow, I go to the user guide and skim and ctrl+f my way around before turning to slack. If this was mentioned in the user guide would've saved me from pestering folks here 😁

peterdee18:06:23

Why is it that I can reference a var in a CLJS repl, but when shadow compiles my code in the same namespace, it may not find that var? My more general question is: how do I reference a var in a namespace that I cannot require because of circularity?

souenzzo18:06:13

TLDR; it is not possible. you may find a few tricks to do, but clojure do not support circularity in general. not sure about closure compiler, but closure compiler makes harder because smashes every var name in your code. One trick: add an export

(ns my.cool-ns)
(def ^:export my-global ...)
then you can access (-> js/global .-my .-cool_ns .-my_global) not tested in newer cljs version. i did this yeeeeaars ago.

peterdee18:06:06

I see. Maybe also something with the namespace object, which seems to carry all the code. (???)

souenzzo18:06:04

namespace is not a thing in clojure you can't pass a namespace as a parameter in clojure code. despite that both in JVM and JS you actually can. because of reasons. but it is not a supported/public api.

souenzzo18:06:53

maybe in the future, with the advance of :as-alias (a new feature from clj 1.11+) circular namespaces will be possible

peterdee18:06:14

I just tried(j/get-in rad-mapper.evaluate ["processRM"]) and was able to run the function "processRM" that evaluated to. NS j is just the applied-science.js-interop.

peterdee18:06:51

Of course, might stop working any day now.

souenzzo18:06:23

@U0D4UL3U2 you need to test with cljs advanced build. I think that the way you did only works in non-optimized builds

souenzzo18:06:10

(or say that you dont care about your app size and do not use advanced at-all. more people than I would like do that)

souenzzo18:06:36

advanced build = release in shadow

peterdee18:06:37

Yeah, makes sense. Good enough for today's demo I think running under shadow-cljs watch, I think. :face_with_peeking_eye:

🚀 1
peterdee18:06:56

Cancel that. Only works in repl.

verysweat_g 1
souenzzo18:06:40

don't being afraid of the interop (some-> js/window .-rad_mapper .-evaluate .-processRM)

peterdee18:06:31

In compiled code I get "Cannot infer target type"

souenzzo18:06:47

add a few random ^js

souenzzo18:06:08

(some-> ^js js/window ^js .-rad_mapper ^js .-evaluate ^js .-processRM)

peterdee19:06:20

(let [^js process-rm (some-> ^js js/window ^js .-rad_mapper ^js .-evaluate ^js .-processRM)]
-----------------------------------^--------------------------------------------
Cannot infer target type in expression (. G__79695 -processRM) The pointer is at (some

souenzzo19:06:19

hummm ns .. :require [[goog.object :as gobj]] (gobj/getValueByKeys js/window "rad_mapper" "evaluate" "processRM")

peterdee19:06:45

That worked! Thanks!😄

🚀 1
peterdee00:06:23

To be clear. It worked well enough for the demo. As you suggested, it doesn't work on under a release compile. I think that's going to be okay because the code I'm trying to run runs under the Small Clojure Interpreter (SCI) and I think I can untangle my use of SCI from these namespaces.

kanwei19:06:18

Updated to 2.24 and seeing this error:

require "./useCallbackRef" for package "/Users/xxx/node_modules/@restart/hooks" not exported
{:rel-require "./useCallbackRef", :package-dir #object[java.io.File 0x4f9ae00a "/Users/xxx/node_modules/@restart/hooks"], :exports {"." {"types" "./esm/index.d.ts", "import" "./esm/index.js", "require" "./cjs/index.js"}, "./*" {"types" "./esm/*.d.ts", "import" "./esm/*.js", "require" "./cjs/*.js"}}}
ExceptionInfo: require "./useCallbackRef" for package "/Users/xxx/node_modules/@restart/hooks" not exported

scarytom09:06:46

I'm also seeing the same issue since upgrading:

require "./lib/languages/clojure" for package "/home/xxx/yyy/node_modules/highlight.js" not exported

scarytom09:06:07

A little binary chopping indicates the issue was introduced in v2.23.6

scarytom09:06:44

@U05224H0W you seem to have been doing quite a bit with package.json exports recently, is there something we should be doing differently following these changes?

thheller09:06:37

until then you can set :js-options {:ignore-exports true} in the build config

thheller09:06:45

I didn't expect wildcard exports to be so common, thought we could do without but apparently not

scarytom09:06:08

no worries—thanks for the quick response.

pez20:06:01

For defines, the shadow-cljs repl returns the value being bound in a vector, instead of the var. Reported on Calva here: https://github.com/BetterThanTomorrow/calva/issues/2228 Expected:

(def a 1) => #'cljs.user/a
Actual:
(def a 1) => [1]
It seems to have been introduced somewhere between 2.19.9 and 2.23.3. I can bisect it further if that is helpful?

hifumi12300:06:35

IIRC that’s a setting tweakable in a CLJS REPL, not really a bug with shadow-cljs. I remember seeing something like being able to configure how the CLJS REPL decides to print a var

hifumi12300:06:54

After experimenting with :def-emits-var, I take back my statement. I thought it would’ve been related to that. But I see this in Emacs as well

pez10:06:17

Did you catch this post, @U05224H0W? I don’t mean to nag. It’s not a big problem. Just want to check if you’re aware.

thheller10:06:08

its just a printing issue. I made some changes for the Inspect UI, and one of those changes was defaulting to showing datafy'd output

thheller10:06:42

the REPL was a accidental victim for that too, but so far didn't get any complaints

thheller10:06:20

so what you are seeing is just a datafied var, where the default implementation wraps that in a vector, just like atoms

thheller10:06:37

its still just a regular var, so all working fine 😛

pez10:06:33

Certainly. Things work fine and I have not really noticed this until it was pointed out to me. However, I imagine it could be problematic if a REPL output consumer is not a human. Would you consider a PR restoring the old REPL output?

thheller10:06:26

no PR necessary. just open an issue so I don't forget. I've been meaning to fix it, just forgot.

👍 2
thheller10:06:45

might get to it later today

pez10:06:11

Issue filed. 😃

carnundotcom22:06:38

Hi all. Anyone else had trouble requiring local deps in an esm module, i.e. a chrome extension popup (as per https://github.com/thheller/chrome-ext-v3), and know of a fix? Currently, my shadow-cljs.edn sets {:deps true ...} and deps.edn has a {:deps {foo/foo {:local/root "../bar"}}. The whole thing compiles just fine, but when I try to open the popup I get Failed to load resource: net::ERR_FILE_NOT_FOUND in the console—and indeed the required namespace has no equivalent .js in the given :output-dir: ⬇️ Is there something additional I'd need to do to make this dep available? (Other, regular deps e.g. Reagent are all good.)

thheller04:06:46

chrome exts are very picky about loading files. did you reload the extension properly? this has to be done manually unfortunately. so every change you make cannot be hot loaded or anything, you actually need to manually reload it.

thheller04:06:24

otherwise everything should be there. assuming it was required by the build in a regular require and so on

thheller04:06:31

local deps work just like any other dep, so that should not be a factor

thheller05:06:05

which version do you use though? I made a few changes to :esm recently, could be that you are using a bad one?

thheller05:06:52

btw in case it was unclear I updated the docs a little

thheller05:06:17

you don't have to use the clj command line switch just to run with deps.edn. that is optional.

thheller05:06:16

I tested with 2.24.0 and everything is still working fine in the demo

carnundotcom10:06:23

yep, reloaded must be a mistake in the dep, hmm

carnundotcom10:06:55

as for version, it's "2.23.8" (maven); so I'll see if bumping makes a difference

carnundotcom10:06:00

different problem after bumping :thinking_face:

carnundotcom10:06:49

is it :deps {:aliases [:cljs]} that allows running shadow-cljs as normal then? 🙂

carnundotcom10:06:58

nothing wrong with the local dep / require afaict but still no corresponding compiled js

carnundotcom10:06:09

reagent problem unrelated I suspect

carnundotcom10:06:21

Huh. After removing the extension and re-`Load unpacked`ing, all is now fine.

carnundotcom10:06:59

Hope I don't have to do that after every change! 😅

carnundotcom10:06:24

Apparently not. Just reload. Nice.

carnundotcom10:06:32

god extensions are annoying

carnundotcom10:06:33

but thanks for your help @U05224H0W!

carnundotcom10:06:34

but evidently not just reload for some things

carnundotcom10:06:46

(spotty signal on a train; messages may be arriving out of order)

thheller11:06:27

yeah the chrome exts with v3 manifests got even stricter, so we can't do any hot-reload or REPL anymore since eval is forbidden

thheller11:06:53

and it only sees files that were present when the extension was first loaded

thheller11:06:03

changes made afterwards lead to sort of chaos

thheller11:06:54

:deps {:aliases [:cljs]} is all yes. well in your fork you called the alias :shadow-cljs and had :main-opts in there. should remove :main-opts if you intend to run with just shadow-cljs, and change to match the alias name of course

👍 2
carnundotcom11:06:40

> and it only sees files that were present when the extension was first loaded > changes made afterwards lead to sort of chaos 🙃 good to know!