shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Janne Sauvala 2021-05-01T17:31:12.105500Z

Hi, I’m trying get the CLJS bootstrap repl to work via shadow.cljs.bootstrap.node. I was checking the post here https://code.thheller.com/blog/shadow-cljs/2017/10/14/bootstrap-support.html for some tips. When I try to eval something I get

[:result {:error #error {:message "Could not eval [test]", :data {:tag :cljs/analysis-error}, :cause #error {:message nil, :data {:clojure.error/source nil, :clojure.error/line 1, :clojure.error/column 1, :clojure.error/phase :compilation}, :cause #error {:message "Cannot read property 'findInternedVar' of null at line 1 ", :data {:file nil, :line 1, :column 1, :tag :cljs/analysis-error}, :cause #object[TypeError TypeError: Cannot read property 'findInternedVar' of null]}}}}]
Can you see if there is something wrong with my configs or code:

Janne Sauvala 2021-05-01T17:31:44.105700Z

code:

require these:
[cljs.js :as cljs]
[cljs.env :as env]
[shadow.cljs.bootstrap.node :as shadow.bootstrap]
...
(defn print-result [{:keys [error value] :as result}]
  (prn [:result result]))

(def code "(+ 1 2)")

(defonce compile-state-ref (env/default-compiler-env))

(defn compile-it []
  (cljs/eval-str
   compile-state-ref
   code
   "[test]"
   {:eval cljs/js-eval
    :load (partial shadow.bootstrap/load compile-state-ref)}
   print-result))

(shadow.bootstrap/init compile-state-ref
                       {:path "out/extension/bootstrap"}
                       compile-it)

(compile-it)

Janne Sauvala 2021-05-01T17:32:08.105900Z

And shadow-cljs.edn build section:

:builds
{:dev {:target :node-library
       :output-to "out/extension/extension.js"
       :output-dir "out/extension"
       :exports-var prode.extension/exports
       :devtools {:repl-pprint true}
       :compiler-options {:source-map-detail-level :all
                          :output-wrapper false
                          :optimizations :simple}}

 :bootstrap {:target :bootstrap
             :output-dir "out/extension/bootstrap"
             :entries [cljs.js]
             :macros []
             :exclude #{cljs.js}
             :compiler-options {:warnings {:infer false}
                                :optimizations :simple}}}

thheller 2021-05-01T18:39:02.106400Z

You can't do this (compile-it) until the above init has completed

thheller 2021-05-01T18:39:08.106600Z

so you are just calling it too early

thheller 2021-05-01T18:39:21.106800Z

init will already call it when its done

Janne Sauvala 2021-05-01T18:47:41.107Z

I moved calling that function inside a comment block and evaluated it from there. This gives me the same error message. If shadow.bootstrap/init is going to run the compile-it, where should I see the result (it’s not printed to the REPL)?

Janne Sauvala 2021-05-01T18:55:12.107200Z

I changed the call-back function to a new function that would print something, and now I see some errors in the node-env’s (it is actually a vscode debug instance) logs something

[2021-05-01 21:53:18.838] [renderer11] [error] transit-load failed: Error: transit-load failed
    at new cljs$core$ExceptionInfo (/Users/janne/Dev/clojure/prode/out/extension/cljs-runtime/cljs/core.cljs:11455:1)
    at Function.cljs$core$IFn$_invoke$arity$3 (/Users/janne/Dev/clojure/prode/out/extension/cljs-runtime/cljs/core.cljs:11484:1)
    at Function.cljs$core$IFn$_invoke$arity$2 (/Users/janne/Dev/clojure/prode/out/extension/cljs-runtime/cljs/core.cljs:11484:1)
    at ReadFileContext.callback (/Users/janne/Dev/clojure/prode/out/extension/cljs-runtime/shadow/cljs/bootstrap/node.cljs:38:9)
    at FSReqCallback.readFileAfterOpen [as oncomplete] (fs.js:265:13)
    at FSReqCallback.callbackTrampoline (internal/async_hooks.js:120:14)

hadils 2021-05-01T19:42:10.110Z

Hi. I have an Expo app that I just ejected to bare workflow, so now it's plain React Native. I am wondering what is the best way to create an App.js in my directory. Can I automate it with shadow-cljs?

thheller 2021-05-01T19:48:59.110200Z

well you removed a couple things from the config

thheller 2021-05-01T19:49:12.110700Z

so I'm guessing your server isn't setup correctly

hadils 2021-05-01T19:49:21.111Z

NVM, I figured it out. I need to point shadow-cljs.edn to the. App/ build dir.

thheller 2021-05-01T19:49:26.111100Z

by default it expects to load stuff from /bootstrap

thheller 2021-05-01T19:50:05.111300Z

but seems like you are loading it in node?

thheller 2021-05-01T19:50:39.111500Z

oh right I missed that

thheller 2021-05-01T19:50:49.111700Z

I'm guessing your paths aren't quite right?

thheller 2021-05-01T19:51:23.112100Z

sorry I don't have a clue what an ejected app looks like

Janne Sauvala 2021-05-01T20:05:16.112200Z

I won’t rule that option out 😄 I have been trying with different paths but I haven’t been able to find a working setup. The dev-build output the build stuff to out/extension and the output is inside that one out/extension/bootstrap. Did you mean that bootstrap should go actually on the same level as the out folder (project root)?

thheller 2021-05-01T20:07:31.112500Z

:path "out/extension/bootstrap"

thheller 2021-05-01T20:08:07.112700Z

how do you run the stuff anyways? from "extension" I gather its not regular node?

Janne Sauvala 2021-05-01T20:09:25.112900Z

This is something I have been experimenting. To create a VSCode extension that would execute cljs via the bootstrap repl. So the output js is loaded to vscode as an extension

thheller 2021-05-01T20:09:51.113100Z

hmm yeah no clue if the bootstrap.node will work there

Janne Sauvala 2021-05-01T20:10:57.113300Z

it could work like a normal node env but it might have some differences. Maybe I try to get this working in normal node first. Then I can check if everything is okay on vscode side

thheller 2021-05-01T20:11:08.113500Z

maybe try not setting :path at all? it defaults to this https://github.com/thheller/shadow-cljs/blob/015926609e1c070de57efa71646c46f92f08d7d9/src/main/shadow/cljs/bootstrap/node.cljs#L13

thheller 2021-05-01T20:11:34.113800Z

maybe you need a similar path/resolve call

Janne Sauvala 2021-05-01T20:12:03.114Z

Yea, I could try that

Janne Sauvala 2021-05-01T20:14:38.114200Z

That worked! I removed the :path and it is working 🙂

👍 1
Janne Sauvala 2021-05-01T20:17:51.114400Z

So many thanks for the help 🙂