Fork me on GitHub
#shadow-cljs
<
2021-05-01
>
Janne Sauvala17:05:12

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 Sauvala17:05:44

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 Sauvala17:05:08

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}}}

thheller18:05:02

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

thheller18:05:08

so you are just calling it too early

thheller18:05:21

init will already call it when its done

Janne Sauvala18:05:41

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 Sauvala18:05:12

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)

thheller19:05:59

well you removed a couple things from the config

thheller19:05:12

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

thheller19:05:26

by default it expects to load stuff from /bootstrap

thheller19:05:05

but seems like you are loading it in node?

thheller19:05:39

oh right I missed that

thheller19:05:49

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

Janne Sauvala20:05:16

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)?

thheller20:05:31

:path "out/extension/bootstrap"

thheller20:05:07

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

Janne Sauvala20:05:25

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

thheller20:05:51

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

Janne Sauvala20:05:57

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

thheller20:05:34

maybe you need a similar path/resolve call

Janne Sauvala20:05:03

Yea, I could try that

Janne Sauvala20:05:38

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

👍 3
Janne Sauvala20:05:51

So many thanks for the help 🙂

hadils19:05:10

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?

hadils19:05:21

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

thheller19:05:23

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