shadow-cljs

itaied 2025-03-04T09:41:25.973909Z

hey all i'm building an esm and require it in a different project when i have an error in the esm code (compiled) i get generated js that i can't figure out the problem can i have a setup where errors in the esm will display in cljs code in the browser?

thheller 2025-03-04T09:42:50.120729Z

define "require it in a different project"? usually you should have source maps, but if by "require" you mean build with another tools they might get lost by that tool

itaied 2025-03-04T09:44:44.789219Z

project: import { appJsonToReactElement } from "/home/itai/dev/ui-framework/dist/app-runner.js"; the project is using vite to build itself

itaied 2025-03-04T09:46:16.321599Z

lib:

{:target     :esm
             :js-options {:js-provider :import}
             :output-dir "dist"
             :compiler-options {:source-map                         true
                                :source-map-include-sources-content true}
             :modules    {:app-runner {:exports {appJsonToReactElement ui-framework.tree.dynamic-runner/appJsonToReactElement}}}
             }

thheller 2025-03-04T09:53:11.167499Z

ok, so you need to setup vite to include the source maps. no clue how you'd do that though.

itaied 2025-03-04T09:54:57.720539Z

ok ill look into that, thank you

Ken Huang 2025-03-04T15:54:55.284499Z

Hi, is it possible to keep a .js file from being minified in a release build? Right now, I temporarily require a .js file in cljs and it works perfectly in :dev build. But in the release build, the json data (e.g. {name, options}) posted to an endpoint is not right as the variable names have been changed. Any advice? thanks!

Ken Huang 2025-03-04T16:51:36.829139Z

Is adding externs the right answer? https://cljs.github.io/api/compiler-options/externs

thheller 2025-03-04T19:55:33.260339Z

> I temporarily require a .js file in cljs

thheller 2025-03-04T19:55:42.151999Z

what does this mean? how do you temporarily require a file?

thheller 2025-03-04T19:56:45.382879Z

yes, externs will probably prevent the renaming, but that'll be a bit cumbersome

Ken Huang 2025-03-05T00:26:03.009549Z

Oh, I meant at the moment by that, because I will translate it to cljs at some point.

Ken Huang 2025-03-05T00:27:42.655709Z

The good news is this is a small js file, so it should be ok.

thheller 2025-03-05T08:27:06.518599Z

if you write the file as commonjs, meaning using exports.foo instead of export foo you by bypass this step entirely

thheller 2025-03-05T08:27:16.972329Z

commonjs does not go through :advanced and thus doesn't need externs

Ken Huang 2025-03-05T08:50:13.377929Z

Okay I will try it, thanks!

Ken Huang 2025-03-05T14:57:21.770669Z

exports.foo doesn't work for me unfortunately, don't know why. And I couldn't find helpful docs about how to write an externs js file properly, at last I tries this trick https://ericnormand.me/article/clojurescript-externs and it worked (simply use the JavaScript library as its own externs file)

Ken Huang 2025-03-05T16:55:24.014119Z

OK, just got the commonjs way work.

Ken Huang 2025-03-05T16:59:55.581009Z

There is a default export in ESM js like export default new Foo(); , and the require form for it is ["./foo.js$default" :as foo] But for commonjs, the export statement is exports.client = new Foo(); , so the require form should be slightly adapted: ["./foo.js" :as foo]``. Maybe I should write a more detailed post.

Ken Huang 2025-03-05T17:01:16.904219Z

BTW, regarding "commonjs does not go through :advanced and thus doesn't need externs", this is a feature of shadow-cljs, right?

thheller 2025-03-05T17:35:58.372359Z

yes, this entire way of directly using .js files is shadow-cljs only

👍 1