Fork me on GitHub
#clojurescript
<
2022-06-05
>
lilactown03:06:19

I have the following code that I want to compile and run on node.js

(ns fixtures.kitchen-sink
  (:require
   ["react" :as react]
   ["react-dom/server" :as rdom]))


(defn -main []
  (prn (rdom/renderToString (react/createElement "div" nil "hi"))))

lilactown03:06:46

if I try and require ["react" :as react] in another ns, however, it fails

lilactown03:06:55

(ns fixtures.asdf
  (:require
   ["react" :as react]))


(react/createElement "div" nil "foo")
and then
(ns fixtures.kitchen-sink
  (:require
   fixtures.asdf
   ,,,)

lilactown03:06:44

$ clojure -A:test -m cljs.main -m fixtures.kitchen-sink -re node
WARNING: Implicit use of clojure.main with options is deprecated, use -M
(node:14799) [DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead. (Triggered by calling <anonymous> on process.)
(Use `node --trace-deprecation ...` to show where the warning was created)
Execution error (ExceptionInfo) at cljs.repl/evaluate-form (repl.cljc:577).
Execution error (Error) at (<cljs repl>:1).
Cannot find module 'react'
Require stack:
- /private/var/folders/07/jvdsvczj0975zzwkmwj23ydh0000gn/T/out825168205526329496285569366295375/fixtures/arst.js

lilactown03:06:54

any insights into how I can fix this?

thheller06:06:50

@lilactown looks like the JS is run in some temp folder. look for a setting that would change it so it runs in your project? maybe the output-dir setting? dunno what that is for cljs.main but should be something like that?

lilactown16:06:07

yeah I switched to calling cljs.build.api/build directly and then node on the output and it is working

Léo Crapart13:06:59

I saw that there is Next that builds upon React, and Nuxt that does same with Vue. Is there anything similar that builds upon Re-frame to make a multipage web app with clojurescript ?

p-himik13:06:21

Not really. SSR is a pain in the general case.

Michaël Salihi18:06:18

@U03HPBZUNS2 Do you know Inertia.js? It's a solution that allows you to handle most of the work at the backend level, thus simplifying the front-end and managing the SSR. https://inertiajs.com/

👍 1
Michaël Salihi18:06:51

I wrote this Clojure adapter: https://github.com/prestancedesign/inertia-clojure I haven't documented SSR yet but you can check out the ssr branch of this demo app: https://github.com/prestancedesign/pingcrm-clojure/tree/ssr

Léo Crapart22:06:25

Very nice, and can I deploy it on vercel, netlify, githubpages or something like that ? or I have to deploy it on a server like DigitalOcean ?

Michaël Salihi08:06:08

Thanks 🙂 Yes for sure, you can deploy on Netlify and DigitalOcean. The PingCRM demo is currently running on DO. AFAIK, for Vercel it's not possible. There is no Clojure/JVM runtimes for the back end. LMK if you have some questions.