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?
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?
no
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
you debug this by checking what your browser says
it'll usually give a you 404 errors or so
If there is a hyphen or underscore anywhere, try removing it. In fact, for extra safety, stick to letters between b and y.
Hyphen or underscore where?
stop distracting
the only possible issue is a path mismatch
or how does it manifest that "source maps don't work"?
I don’t see any 404. The source maps are produced, side by side with the js files, as normal.
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?
The trace looks like so:
This is just me evaluating a throw.
hmm yeah that should be mapped
in the chrome console tab. on the top right corner for my is a "Default levels" drop down. Is "Info" activated?
IIRC chrome prints source map 404 at the info level
All levels are activated.
what is the path of the loaded JS?
http://localhost:8750/js/compiled/main.js and in the file system that is public/js/compiled/main.js
what happens if you load http://localhost:8750/js/compiled/main.js.map in the browser?
404! hmmm
ehm no wait this is a dev build
http://localhost:8750/js/compiled/cljs-runtime/cljs.core.js.map
That loads the source map
and what is the configured :asset-path in the build config, if any?
public/js/compiled
ok that is incorrect. should be /js/compiled as that is the path the files are loaded from over http
not the same as :output-dir
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. 🙏
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.that means you must use :target :esm because otherwise node is unhappy
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
Yay! Now my tests run again, using the js-options option.
Curious, can shadow still run tests if I use the esm target?
: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
yes, you can in theory still run tests, just not as convenient as :node-test