cljs-dev

thheller 2023-06-20T09:09:15.381169Z

what even is this "exports" value https://unpkg.com/@babel/runtime@7.22.5/package.json the JS world really keeps adding one nonsensical thing after the other ... 🤮

😭 2
borkdude 2023-06-20T09:16:03.344329Z

let JS deal with JS and don't try to understand it, is my mantra ;)

thheller 2023-06-20T09:16:35.519389Z

that doesn't help trying to implement this mess unfortunately 😛

borkdude 2023-06-20T09:16:59.669649Z

don't implement it, but let JS tools complain about themselves, just compile to JS and then let those tools deal with the mess

thheller 2023-06-20T09:17:49.422329Z

unfortunately more and more packages are starting to use "exports". so for shadow-cljs to bundle them I kinda have to.

thheller 2023-06-20T09:18:11.331099Z

not yet at the point where I'm giving up and discontinuing the JS support in shadow-cljs, although its close 😉

😱 2
😅 1
borkdude 2023-06-20T09:28:55.849069Z

btw, off topic, but: I just tried to upgrade clerk from shadow 2.23.1 to the newest, it uses target esm, but viewing a notebook failed, not sure if it rings a bell, but I'll try to make a proper repro

thheller 2023-06-20T09:30:20.918859Z

the actual error would help. "notebook failed" doesn't mean anything to me. I changed how esm code is loaded because of problems in node, totally possible I accidentally broke something

borkdude 2023-06-20T09:30:34.753489Z

yeah, I know :)

borkdude 2023-06-20T09:30:42.928369Z

will look into it now

borkdude 2023-06-20T09:31:16.009609Z

perhaps it's fixed in .5 which wasn't there yesterday, I'll try it

borkdude 2023-06-20T09:34:02.053079Z

so I'm getting this with .4 in watch mode: I'll now try .5

borkdude 2023-06-20T09:36:56.254539Z

no dice with .4 either. I'll try to backtrack and continue in #shadow-cljs

thheller 2023-06-20T09:37:21.760929Z

seems to me like those files should exist?

borkdude 2023-06-20T09:41:20.139349Z

dunno. with .3 I can get it working

thheller 2023-06-20T10:22:34.350389Z

can't really tell what those paths are supposed to be. they are weirdly truncated, whats the actual url?

borkdude 2023-06-20T10:29:48.291179Z

in clerk development: http://localhost:7777/notebooks/dice.clj

thheller 2023-06-20T10:40:45.398999Z

no I mean the 404 urls, like what is the full url of the first react_production.min.js?

borkdude 2023-06-20T10:43:04.586059Z

something like this:

thheller 2023-06-20T10:43:50.311319Z

ah nvm, I can reproduce. its not accounting for eliminated JS deps. ie. this is a dev build, it shouldn't try to load the min file

borkdude 2023-06-20T10:45:27.654209Z

nice

thheller 2023-06-20T10:49:26.412699Z

try 2.23.6

borkdude 2023-06-20T11:02:05.815389Z

Failed to inspect file
  /Users/borkdude/dev/clerk/node_modules/tslib

FileNotFoundException: /Users/borkdude/dev/clerk/node_modules/tslib (Is a directory)
	java.io.FileInputStream.open0 (FileInputStream.java:-2)
	java.io.FileInputStream.open (FileInputStream.java:219)
	java.io.FileInputStream.<init> (FileInputStream.java:158)
	 (io.clj:231)
	 (io.clj:231)
	 (io.clj:71)
	 (io.clj:167)
	 (io.clj:167)
	 (io.clj:71)

borkdude 2023-06-20T11:02:32.383259Z

I can paste more of the stack trace if you want

thheller 2023-06-20T11:40:11.693349Z

yes, without that I cannot tell why it failed

thheller 2023-06-20T11:42:22.562109Z

if its exports related you can set :js-options {:ignore-exports true}. that'll make it go back to old behavior

thheller 2023-06-20T11:42:44.854559Z

I tested exports stuff on a bunch of packages but far from all of them. absolutely expected to fail in some cases

borkdude 2023-06-20T11:43:57.760319Z

here you go: https://gist.github.com/borkdude/14e8b6b996369249224e01bb60a56197

thheller 2023-06-20T11:56:36.007279Z

absolutely gotta love this mess https://unpkg.com/tslib@2.5.3/package.json

thheller 2023-06-20T11:56:55.338659Z

"./": "./"
what is that even supposed to mean ...

😱 2
borkdude 2023-06-20T11:57:40.506799Z

don't shoot the messenger :)

thheller 2023-06-20T12:06:06.917309Z

try 2.23.7 or set :js-options {:ignore-exports true} if you want to avoid further issues

thheller 2023-06-20T12:06:13.039289Z

I'll do some more testing myself later I guess

borkdude 2023-06-20T12:26:37.532249Z

next error: https://gist.github.com/borkdude/880c918ca22f3ac94a74d592b31b5863

thheller 2023-06-20T12:36:10.029629Z

doh, try 2.23.8

borkdude 2023-06-20T12:38:14.116989Z

next error: https://gist.github.com/borkdude/b247637e497e8e52dcdce3b2f62ec94f

thheller 2023-06-20T12:39:18.531499Z

> This file is being treated as an ES module because it has a '.js' file extension and '/Users/borkdude/dev/clerk/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

thheller 2023-06-20T12:39:28.729579Z

ESM is nothing but trouble 😛

thheller 2023-06-20T12:40:00.016619Z

I guess due to exports its now using ESM code where it previously wasn't, and that still runs through babel

thheller 2023-06-20T12:41:18.219189Z

can you do a quick test and cd .shadow-cljs/babel-worker/; npm init -y and run again? guess that won't do anything though. guess I'll rename it to .cjs

thheller 2023-06-20T12:42:13.754879Z

wonder why this didn't happen before

borkdude 2023-06-20T12:45:35.361519Z

That seems to cause the build to succeed, but I still get this error at runtime:

Group.mjs:1 Uncaught TypeError: (0 , React.forwardRef) is not a function
    at shadow$provide.module$node_modules$framer_motion$dist$es$components$Reorder$Group_mjs (Group.mjs:1:132)
    at shadow.js.jsRequire (js.js:74:17)
    at shadow$provide.module$node_modules$framer_motion$dist$es$components$Reorder$index_mjs (index.mjs:1:132)
    at shadow.js.jsRequire (js.js:74:17)
    at shadow$provide.module$node_modules$framer_motion$dist$es$index_mjs (index.mjs:1:113)
    at shadow.js.jsRequire (js.js:74:17)
    at shadow.js.require (js.js:112:1)

borkdude 2023-06-20T12:45:39.474899Z

in the browser

thheller 2023-06-20T12:46:51.318399Z

I guess all this confirms that suspicion https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/build/npm.clj#L971-L973

thheller 2023-06-20T12:46:58.879119Z

still can't reliably mix commonjs and esm code

thheller 2023-06-20T12:47:29.041019Z

can you try :js-options {:export-conditions ["require" "browser" "default"]} ?

borkdude 2023-06-20T12:48:16.764569Z

Will do. This is the total config:

{:deps {:aliases [:sci]}
 :dev-http {7778 {:roots ["public" "classpath:public"]}}
 :nrepl false
 :builds {:viewer {:target :esm
                   :runtime :browser ;; `:custom` needed when developing ssr, will see WebSocket errors without it
                   :output-dir "public/js"
                   :release {:output-dir "build/"}
                   :compiler-options {:source-map true}
                   :dev {:modules {:viewer {:entries [devtools]}}}
                   :modules {:viewer {:entries [nextjournal.clerk.sci-env
                                                nextjournal.clerk.trim-image]}}
                   :js-options {:output-feature-set :es8
                                :export-conditions ["require" "browser" "default"]}
                   :build-hooks [(shadow.cljs.build-report/hook
                                  {:output-to "report.html" :print-table true})]}}}

borkdude 2023-06-20T12:48:53.548989Z

it worked

thheller 2023-06-20T12:51:24.668839Z

good to know. thanks.

2023-06-20T16:48:46.740229Z

> still can’t reliably mix commonjs and esm code webpack does this though doesn’t it? ie. it supports bundling libs that can be a mix of esm & cjs modules?

2023-06-20T16:49:55.850579Z

> unfortunately more and more packages are starting to use “exports”. so for shadow-cljs to bundle them I kinda have to. Indeed this has been coming up often with me lately. I’ve just been overwriting webpack resolve.alias to ignore package exports in several cases - and I just manually point it at where to look in the lib distribution. This is also brittle to if they move things around later. ☠️