shadow-cljs

smniel 2025-01-30T01:27:35.768079Z

Hi! I have put together an app where we are building out new functionality in clojurescript, but also embedding an older javascript app inside. This has worked well and we have been able to work with the few constraints when building javascript sources. These sources are themselves first compiled from javascript, typescript, and vue files. The compilation is creating a sourcemap. It will be very beneficial to have these sourcemaps be used, so we can easily see the original sources (1000s of files) rather than the few that they are bundled down to before being compiled with shadow. I stumbled on https://clojureverse.org/t/using-original-js-source-maps/6469, which gave me some hope, but I see that these changes donโ€™t seem to be in the current version of shadow anymore. Does anyone know of the current state of using sourcemaps for javascript sources going into shadow? Are there any pointers on how I can make this work?

๐Ÿ‘€ 1
thheller 2025-02-03T11:44:28.496249Z

input source maps kinda do not work. I tried a couple times getting them to work, but unfortunately that feature isn't very accessible inside the closure compiler. some behavior is hardcoded and doesn't match how shadow-cljs uses the actual closure compiler. adjusting that didn't seem feasible without modifications in the closure compiler itself, at least the last time I checked. It has been a while though. maybe you'd have more luck integrating the CLJS outputs in the JS build instead?

smniel 2025-02-03T18:33:58.583649Z

Ok. Iโ€™ll have to see if I can get it working the other direction sometime. Thank you for the reply and for sharing shadow with all of us!

smniel 2025-01-30T01:33:17.116789Z

When I have the sourcemaps as sibling files in the directory. I get a log message from shadow that it failed to find them (so it is trying ยฏ\(ใƒ„)/ยฏ ), although, it appears that it is using a path that should successfully be found as a resource from the classpath. When I build the javascript with โ€˜inlineโ€™ sourcemaps (`data:` urls), then it actually fails to compile with a the message no output for id: [:shadow.build.classpath/resource "file/that/exists.js"].

smniel 2025-01-30T01:33:50.889119Z

Thanks in advance for any help or pointers on the current state of things or constraints to making these work.

smniel 2025-01-30T01:46:13.041059Z

The logs when the sourcemaps are sibling files is the following:

[shadow:watch         ] ------ WARNING #1 -  -----------------------------------------------------------
[shadow:watch         ]  Resource:
[shadow:watch         ]  Failed to resolve sourcemap at file/that/exists.js.map: file/that/exists.js.map
[shadow:watch         ] --------------------------------------------------------------------------------

manas_marthi 2025-01-30T05:05:30.060479Z

Hi, I found that npm package sqlite-async offers ES6 promises based wrapper to sqlite3 core driver that uses callbacks. I included both in my package.json. In my repl, I am getting an error when I use (require ["sqlite-async":as mysqlite])

REPL Invoke Exception Error [ERR_REQUIRE_ESM]: require() of ES Module sqlite-async.js from shadow-cljs-express/[stdin] not supported.
; Instead change the require of sqlite-async.js to a dynamic import() which is available in all CommonJS modules.
; 
Can someone advise how to use deal with these errors.

manas_marthi 2025-01-30T08:14:50.622079Z

I tried (js/import "sqlite-async" no luck

thheller 2025-01-30T08:19:03.558519Z

:js-options {:module-rules {"sqlite-async" {:type :esm}}} hilarious. this does not and has never existed ๐Ÿ˜›

thheller 2025-01-30T08:19:39.609839Z

:esm does not currently support a REPL for ndoe targets, so this will not work

thheller 2025-01-30T08:19:55.633889Z

you can still use the regular build just fine though. just can't do anything at the repl

thheller 2025-01-30T08:20:07.285319Z

:js-options {:module-type :es6} also doesn't exist

thheller 2025-01-30T08:20:22.288029Z

and the build config is missing the :modules config

thheller 2025-01-30T08:20:40.395379Z

see the example here https://clojureverse.org/t/generating-es-modules-browser-deno/6116

manas_marthi 2025-01-30T08:38:02.028949Z

I took those options based on Claude AI advice. When I looked in manual they were not there. I thought it must be undocumented option. Turns out it is just LLM hallucination. I see an old response from you on clojureverse where you mentioned require of ES modules is not supported is a node issue

manas_marthi 2025-01-30T08:38:08.403569Z

I will try the build

thheller 2025-01-30T08:44:33.847339Z

:esm is the correct choice to get around the node limitation, just need to use config options that actually exist ๐Ÿ˜›

๐Ÿ‘๐Ÿฝ 1
thheller 2025-01-30T08:44:59.304689Z

:use-node-modules true has also never existed

manas_marthi 2025-01-30T05:10:19.070109Z

My shadow-cljs.edn as support for es6 I guess

{:dependencies
 [[org.clojure/core.async "1.7.701"]
  [hiccup "2.0.0-RC4"]
  [funcool/promesa "11.0.678"]]

 :source-paths
 ["src"]

 :builds
 {:app {:target :esm 
        :output-to "target/app.js"
        :output-dir "out"
        :main mynodeapp.main/main
        :js-options {:module-type :es6}
        :compiler-options {:output-feature-set :es-next  ; Use modern JS features
                           :use-node-modules true}

manas_marthi 2025-01-30T06:27:31.514869Z

http://Claude.ai suggested to add `:js-options {:module-rules {"sqlite-async" {:type :esm}}} :compiler-options {:infer-externs :auto}` to shadow-cljs.edn

manas_marthi 2025-01-30T06:27:34.608019Z

It did not work