shadow-cljs

zachcp 2025-04-02T15:51:40.000829Z

Hi! I'd like to add [shadcn](https://ui.shadcn.com) components to a UIX project. However, shadcn is distributed as individually installable components that require some additional compilation steps. In particular, shadn defaults to a local install that is not playing nicely with the shadow-cljs compiler. I am wondering if there is a simple step to get these files to be picked up. You can see my initial attempt to override js-options below and in the screenshot. Pointers appreciated. Thank you.

// shadow-cljs.edn
{:builds {:app
          {:target :browser
           :js-options
           {:resolve {"@" {:target :file
                           :file "@"}}}}}}

thheller 2025-04-02T15:54:51.377539Z

doesn't this generate jsx or tsx files? those need to be processed by something else first since shadow-cljs doesn't support those syntaxes

zachcp 2025-04-02T15:55:23.837179Z

I see this prior art: https://clojurians.slack.com/archives/C6N245JGG/p1709586164193269

zachcp 2025-04-02T15:55:39.175159Z

You can get the components as plain JS.

zachcp 2025-04-02T15:55:49.039459Z

( i think )

thheller 2025-04-02T15:56:11.022999Z

can you override the @ or is that hardcoded? could it generate my-ui/components/ui/accordion instead?

zachcp 2025-04-02T15:56:28.294359Z

I think you can do that. Prett sure @ is only a convention.

thheller 2025-04-02T15:56:52.253849Z

I'm asking because I'm not sure if @ is a good name for a directory 😛

zachcp 2025-04-02T15:57:07.738339Z

JS world is .... wild : )

thheller 2025-04-02T15:57:24.909269Z

either way you can generate the files into packages/my-ui, then in the build config use :js-options {:js-package-dirs ["packages" "node_modules"]}

zachcp 2025-04-02T15:58:01.786249Z

ah! okay. Let me give it a go. Thank you

thheller 2025-04-02T15:58:06.659279Z

in the code then (:require ["my-ui/components/ui/accordion" :as x]) and it'll first look in packages/my-ui/components/ui/accordion and if that isn't found in node_modules

thheller 2025-04-02T15:58:49.401189Z

packages/@ is kinda meh but I guess is a valid directory name 😛

thheller 2025-04-02T15:59:02.754659Z

just needs its own dedicated directory somewhere

zachcp 2025-04-02T15:59:51.155969Z

If I can get this to work. I'll make a template to follow allong.

thheller 2025-04-02T15:59:55.827339Z

basically packages becomes our own private local npm repo. you could generate into node_modules/my-ui but npm usually doesn't like you putting files there and will randomly delete them

🙌 1
zachcp 2025-04-02T16:11:59.596429Z

So yeah., you're right. the JS options are still JSX:.

thheller 2025-04-02T16:13:27.703969Z

you can run that through babel or something. just needs the jsx -> js conversion somehow

thheller 2025-04-02T16:14:13.880029Z

many years ago I documented this https://shadow-cljs.github.io/docs/UsersGuide.html#_javascript_dialects

thheller 2025-04-02T16:14:21.286919Z

no clue if that still works 😛

Nikolas Pafitis 2025-04-02T19:25:04.128329Z

How do i develop node-script with REPL through shadow-cljs? Since there's no runtime like in a browser

thheller 2025-04-02T19:57:02.695129Z

you launch the node script output, then there is the node js runtime, node the-output.js

thheller 2025-04-02T19:57:11.652139Z

or your use npx shadow-cljs node-repl

🙌 1
Nikolas Pafitis 2025-04-02T20:20:00.861219Z

I'm having issues trying to do a node script in cljs using shadow-cljs and having npm dependencies that are ES modules

thheller 2025-04-02T20:21:08.435289Z

that is a node issue that shadow-cljs cannot do anything about with :node-script. if you must use es modules use :target :esm instead

Nikolas Pafitis 2025-04-02T20:21:52.241489Z

I'm trying to figure out :target :esm but I'm not really sure what I'm supposed to add in :modules

Nikolas Pafitis 2025-04-02T20:22:09.683269Z

is there an example?

thheller 2025-04-02T20:22:54.505379Z

:modules {:main {:init-fn }} creates a main.js in :output-dir

thheller 2025-04-02T20:23:04.717599Z

and calls () on startup

Nikolas Pafitis 2025-04-02T20:23:23.084539Z

Well now I'm getting this issue

The required JS dependency "node:stream" is not available, it was required by "node_modules/ink/build/render.js".

thheller 2025-04-02T20:23:35.745649Z

:js-options {:js-provider :import} in the build config

thheller 2025-04-02T20:23:53.250889Z

default for :esm is to bundle dependencies, which it cannot do for node built-ins

Nikolas Pafitis 2025-04-02T20:24:16.736839Z

SyntaxError: Cannot use import statement outside a module

thheller 2025-04-02T20:24:36.952349Z

set "type":"module" in your package.json

Nikolas Pafitis 2025-04-02T20:25:26.527539Z

and if i want to run it i just run the output with node?

thheller 2025-04-02T20:25:47.932099Z

hmm?

Nikolas Pafitis 2025-04-02T20:25:48.084619Z

var SHADOW_IMPORT_PATH = __dirname + '/../.shadow-cljs/builds/memehunter/dev/out/cljs-runtime';
                         ^

ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/nikolaspafitis/IdeaProjects/memehunter/package.json' contains "type": "module".

Nikolas Pafitis 2025-04-02T20:26:13.015009Z

How can i run that script

Nikolas Pafitis 2025-04-02T20:26:26.914389Z

the resulting js script using node

thheller 2025-04-02T20:26:56.004129Z

that is not from a :esm output?

Nikolas Pafitis 2025-04-02T20:27:13.618969Z

Sorry ignore the above

Nikolas Pafitis 2025-04-02T20:27:24.951089Z

node target/app.js


/Users/nikolaspafitis/IdeaProjects/memehunter/node_modules/react-reconciler/cjs/react-reconciler.development.js:491
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
                                             ^

TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner')
    at $$$reconciler (/Users/nikolaspafitis/IdeaProjects/memehunter/node_modules/react-reconciler/cjs/react-reconciler.development.js:491:46)
    at file:///Users/nikolaspafitis/IdeaProjects/memehunter/node_modules/ink/build/reconciler.js:61:16

Node.js v20.15.1

Nikolas Pafitis 2025-04-02T20:28:04.922189Z

I'm trying to build a TUI using uix react and ink

thheller 2025-04-02T20:28:13.553529Z

🤷‍♂️

thheller 2025-04-02T20:29:07.583149Z

thats node, not shadow-cljs

Nikolas Pafitis 2025-04-02T20:29:39.759929Z

Okay thanks

Nikolas Pafitis 2025-04-02T21:29:07.125459Z

@thheller Hi it turns out ink doesn't work with react 19, had to downgrade to 18 your solution worked

👍 1