shadow-cljs

pez 2025-02-17T13:31:14.669639Z

Source maps doesn’t work for me in a new project I am setting up. It’s extra funny because it works in the project I am copying. I don’t know where to even begin trying to fix it. Any ideas anyone?

pez 2025-02-17T13:35:21.049489Z

The only difference I can imagine is remotely related is that the new project has an npm dependency that is an ES module (I think). Could that make shadow skip producing source maps?

thheller 2025-02-17T13:41:45.337489Z

no

thheller 2025-02-17T13:42:13.481569Z

it usually is a path issue. i.e. the files being generated correctly but setting a wrong :asset-path and thus the browser not finding them

🙏 1
thheller 2025-02-17T13:42:26.176049Z

you debug this by checking what your browser says

thheller 2025-02-17T13:42:38.729479Z

it'll usually give a you 404 errors or so

2025-02-17T13:45:54.829849Z

If there is a hyphen or underscore anywhere, try removing it. In fact, for extra safety, stick to letters between b and y.

pez 2025-02-17T13:47:34.659469Z

Hyphen or underscore where?

thheller 2025-02-17T13:48:35.935309Z

stop distracting

thheller 2025-02-17T13:48:41.887889Z

the only possible issue is a path mismatch

thheller 2025-02-17T13:49:15.565679Z

or how does it manifest that "source maps don't work"?

pez 2025-02-17T13:49:18.467649Z

I don’t see any 404. The source maps are produced, side by side with the js files, as normal.

thheller 2025-02-17T13:50:04.616359Z

is the error thrown deeply in some npm JS library? then it is not expected that source maps work. that has never worked. exceptions thrown in actual CLJS code should be fine?

pez 2025-02-17T13:50:10.650729Z

The trace looks like so:

pez 2025-02-17T13:50:28.389619Z

This is just me evaluating a throw.

thheller 2025-02-17T13:51:10.653739Z

hmm yeah that should be mapped

thheller 2025-02-17T13:51:52.846359Z

in the chrome console tab. on the top right corner for my is a "Default levels" drop down. Is "Info" activated?

thheller 2025-02-17T13:52:11.054229Z

IIRC chrome prints source map 404 at the info level

pez 2025-02-17T13:52:28.258719Z

All levels are activated.

thheller 2025-02-17T13:52:44.994299Z

what is the path of the loaded JS?

pez 2025-02-17T13:53:52.040489Z

http://localhost:8750/js/compiled/main.js and in the file system that is public/js/compiled/main.js

thheller 2025-02-17T13:54:55.015259Z

what happens if you load http://localhost:8750/js/compiled/main.js.map in the browser?

pez 2025-02-17T13:55:48.461629Z

404! hmmm

thheller 2025-02-17T13:55:53.163109Z

ehm no wait this is a dev build

pez 2025-02-17T13:56:41.959059Z

That loads the source map

thheller 2025-02-17T13:57:01.136279Z

and what is the configured :asset-path in the build config, if any?

pez 2025-02-17T13:57:21.963819Z

public/js/compiled

thheller 2025-02-17T13:57:29.863909Z

ok that is incorrect. should be /js/compiled as that is the path the files are loaded from over http

thheller 2025-02-17T13:58:12.326489Z

not the same as :output-dir

pez 2025-02-17T14:01:24.603229Z

Ah, sweet, thanks! That was the only thing that differed from my “template” project. That project is a bit weird for reasons and has the web root in the project root. And I overdid the adaption… Now I have source maps working. 🙏

👍 1
pez 2025-02-17T14:46:02.212009Z

I’m using @lume/kiwi in my project. I can require it like

(:require
   ["@lume/kiwi" :as kiwi] 
in my browser target, but for node-test it fails because ES modules not supported. The error message says I should use a dynamic import, but it is unclear to me how to do that.

thheller 2025-02-17T16:11:30.182889Z

that means you must use :target :esm because otherwise node is unhappy

thheller 2025-02-17T16:12:08.615709Z

or given that the browser target works you can try setting :js-options {:js-provider :shadow :keep-native-imports true} in the :node-test config

pez 2025-02-17T16:21:38.394479Z

Yay! Now my tests run again, using the js-options option.

pez 2025-02-17T16:22:12.337179Z

Curious, can shadow still run tests if I use the esm target?

thheller 2025-02-17T16:29:35.312089Z

:target :esm usually is much more involved than just changing the build target, since it works a bit different and there currently is no explicit test support

thheller 2025-02-17T16:30:09.874789Z

yes, you can in theory still run tests, just not as convenient as :node-test

🙏 1