shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
wombawomba 2020-10-26T10:36:23.136200Z

For JS libraries (e.g. https://github.com/Microsoft/monaco-editor) that offer multiple approaches to modules (AMD, ESM + Webpack, ESM + Parcel, …), which one should I go with if I’m using shadow-cljs?

thheller 2020-10-26T10:38:27.137200Z

IIRC the last time I tried to use that package myself it tried to do a bunch of dynamic import which shadow-cljs doesn't support

thheller 2020-10-26T10:38:42.137500Z

but that has been at least a year so no idea what the current state is

thheller 2020-10-26T10:39:37.137900Z

looks like it still does that crap when it even requires custom webpack config/plugin to use https://github.com/microsoft/monaco-editor/blob/master/docs/integrate-esm.md

thheller 2020-10-26T10:40:26.138700Z

you can just use the AMD version and manually embed it in the page and not in the actual CLJS build

thheller 2020-10-26T10:40:30.138900Z

or use webpack

wombawomba 2020-10-26T10:41:11.139600Z

Phew, that was quick 🙂

wombawomba 2020-10-26T10:42:21.141Z

Anyway great advice, thanks… any reason to pick AMD over webpack or vice versa?

wombawomba 2020-10-26T10:44:02.141500Z

Actually I think I’ll just bite thee bullet and set up webpack as described in https://code.thheller.com/blog/shadow-cljs/2020/05/08/how-about-webpack-now.html

thheller 2020-10-26T10:44:20.141900Z

did you try it without?

thheller 2020-10-26T10:44:27.142200Z

I mean it might work? I don't have a clue

thheller 2020-10-26T10:45:42.142700Z

if you just want an editor in a html page try codemirror. that one works and is used by many people.

thheller 2020-10-26T10:47:02.144Z

from the looks of the ESM docs it seems like it might work

wombawomba 2020-10-26T10:47:04.144100Z

I did try codemirror already actually, but I like the look of monaco so I want to see if I can get that one working instead

wombawomba 2020-10-26T10:48:33.145700Z

I didn’t try it with shadow-cljs yet, but okay. I’ll see if I can get ESM to work with shadow-cljs and fall back to whichever of ASM and webpack I can get working first 😉

thheller 2020-10-26T10:49:17.146Z

getting the worker stuff to work will be the tricky part

thheller 2020-10-26T10:49:21.146200Z

but other than that it seems fine

wombawomba 2020-10-26T10:50:16.146800Z

Alright.. out of curiousity, why would the worker stuff be tricky? Because of something the workers do?

thheller 2020-10-26T10:52:57.147100Z

ok nevermind it is not going to work. I did a quick test and it is importing css. so webpack it is

thheller 2020-10-26T10:53:17.147500Z

worker stuff just needs to be configured, so it just doesn't work out of the box

wombawomba 2020-10-26T10:53:45.148Z

Okay then 🙂

thheller 2020-10-26T10:54:22.148600Z

AMD also works. then you don't even have to setup webpack.

wombawomba 2020-10-26T10:55:39.149600Z

BTW, you wouldn’t happen to have a recommended way of running webpack --watch and shadow-cljs watch? Curious if there’s a way to have both without running two terminal windows

thheller 2020-10-26T11:01:42.149800Z

plenty of ways to do that

thheller 2020-10-26T11:02:24.150200Z

I have used https://github.com/strongloop/node-foreman, https://github.com/mysticatea/npm-run-all and a few others in the past

thheller 2020-10-26T11:02:57.150800Z

nowadays I prefer separate terminals for stuff

wombawomba 2020-10-26T11:05:39.151200Z

Got it

wombawomba 2020-10-26T11:08:06.153200Z

So I got AMD working, but I decided to see if I could go with https://www.npmjs.com/package/@monaco-editor/react instead to save myself from having to write a bunch of glue code. However, when I try to load that, shadow-cljs gives me the following error: browser.cljs:38 Failed to load my-project/monaco.cljs TypeError: Cannot redefine property: DiffEditor. Do you think there’s a way around this, or should I give up? 🙂

wombawomba 2020-10-26T11:08:41.154Z

(sorry for all these questions BTW, I’m new to the JS ecosystem and it’s absolutely bewildering to me)

thheller 2020-10-26T11:08:58.154300Z

its bewildering for everyone 😉

thheller 2020-10-26T11:09:18.154600Z

don't know what that error is. don't know what you are doing in your code

wombawomba 2020-10-26T11:10:03.155300Z

I’m doing (ns my-project.monaco (:require ["@monaco-editor/react" :refer [Editor]])) and then nothing else

thheller 2020-10-26T11:10:44.155500Z

don't know what the react package is doing either

thheller 2020-10-26T11:11:00.155800Z

it likely just wraps the ESM package no?

wombawomba 2020-10-26T11:11:41.156200Z

it seems to use AMD: https://www.npmjs.com/package/@monaco-editor/react#config

wombawomba 2020-10-26T11:13:15.157700Z

Perhaps there’s some sort of conflict happening with some other JS lib I’ve previously run? I’ll see if I can reproduce from a clean slate

thheller 2020-10-26T11:14:04.158Z

it likely isn't worth using the react wrapper

thheller 2020-10-26T11:14:25.158500Z

just write the 5 lines to do that yourself and save the headache of making that lib work

wombawomba 2020-10-26T11:15:04.158700Z

Okay 🙂

Michael W 2020-10-26T19:43:00.162300Z

how can I troubleshoot shadow giving me a stale output error? I see my build running in the web console, with warnings. But when I connect to my app shdow-cljs gives me a stale output error, though the app runs. I cleared my js, and the .shadow-cljs folder and restarted my watch but it still says stale output even though it was forced to recompile everything from complete scratch.

thheller 2020-10-26T20:28:22.162600Z

just make sure you are loading the correct file

thheller 2020-10-26T20:28:44.163200Z

could be loading an old one from a different path or so

thheller 2020-10-26T20:28:55.163500Z

frequently happens if you change you :modules config or :output-dir

thheller 2020-10-26T20:29:15.164Z

or can happen if you have 2 shadow-cljs instances running for your project competing with each other

thheller 2020-10-26T20:29:19.164200Z

make sure there is only one running