Fork me on GitHub
#shadow-cljs
<
2023-08-22
>
Roman Liutikov11:08:04

@thheller is bootstrapped cljs supported in latest shadow-cljs? I'm getting a bunch of Can't take value of macro core/... and No such namespace: core, could not locate core.cljs, core.cljc, or JavaScript source providing "core" errors when running an example in shadow-cljs repo

thheller12:08:23

yes, support has not changed

thheller12:08:27

in what context do you get that?

thheller12:08:27

the above doesn't look like a shadow-cljs error either? 😛

Roman Liutikov12:08:40

I've only followed these instructions from the article

@mhuebert created a standalone example and the shadow-cljs repo itself contains the example above.

You can try it by running

npm install -g shadow-cljs
git clone 
cd shadow-cljs
shadow-cljs watch bootstrap-host bootstrap-support
open 

thheller12:08:50

uhm no clue if that still works. let me check

thheller12:08:20

hmm yeah I get those warnings too I guess

thheller12:08:25

will take a look later

👍 2
thheller19:08:03

should be fixed in 2.25.3

🎉 2
Roman Liutikov01:08:18

One thing I’m not sure about is how to make NPM modules available in bootstrapped env? Currently I’m following the same process: adding module name to :entries in build configuration of the bootstrapped target. Then in bootstrapped env when I evaluate something like “(require react-query)”, it’s not able to find the module. Upon further inspection I’ve found out that the module name in modules index is module$node_modules$react_query$blablabla, obviously using this fully qualified name in require works, but that’s not ideal. Could it be that shadows loader doesn’t rewrite NPM module names to locate them properly in modules index?

thheller04:08:52

yes. regular CLJS handles npm deps entirely differently and I have no clue how you expose it so it is found

thheller04:08:16

the bootstrap target will bundle everything just fine, just not sure how you'd access it from self-host

Roman Liutikov06:08:35

This works in bootstrapped (require [module$node_modules$react_query$lib$index :as rq])

Roman Liutikov06:08:39

and then all NPM stuff goes into build config here

:bootstrap {:target :bootstrap
            :output-dir "out/bootstrap"
            :exclude #{cljs.js}
            :entries [cljs.js "react-query"]
...

thheller06:08:35

what I mean is that the index data generated by the :bootstrap target and loaded at runtime should contain all the info necessary to map react-query to module$node_modules$react_query$lib$index. I just don't know how to the mmake self-host compiler use it

Roman Liutikov07:08:37

ah got it, maybe I can come with something hacky...

Roman Liutikov07:08:05

I also have a problem with bootstrapped and release build, given this config

:playground {:target :browser
               :output-dir "out"
               :asset-path "/out"
               :modules {:main {:entries [uix.playground]}}
               :compiler-options {:output-wrapper false}
               :release {:compiler-options {:output-wrapper false}}}
  :bootstrap {:target :bootstrap
              :output-dir "out/bootstrap"
              :exclude #{cljs.js}
              :entries [cljs.js]
              :compiler-options {:optimizations :simple
                                 :output-wrapper false}
              :release {:compiler-options {:optimizations :simple
                                           :infer-externs true
                                           :output-wrapper false}}}
and this playground code
(ns uix.playground
  (:require [cljs.js :as cljs]
            [cljs.env :as env]
            [shadow.cljs.bootstrap.browser :as boot]))

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


(boot/init compile-state-ref
           {:path "/out/bootstrap"}
           (fn []
             (js/console.log "READY")

             (cljs/eval-str
               compile-state-ref
               "(inc 1)"
               "[playground]"
               {:eval cljs/js-eval
                :load (partial boot/load compile-state-ref)}
               (fn [{:keys [error value] :as result}]
                 (js/console.log error)
                 (js/console.log value)))))
I'm getting goog is not defined at runtime for what seem to be macro namespaces

thheller07:08:33

you are setting the output-wrapper to false

thheller07:08:52

can't do that for self-host builds as everything needs to operate in the global scope

thheller07:08:36

output-wrapper keeps the global scope clean, thus it can't find goog and whatever other namespace roots exist such as cljs

Roman Liutikov07:08:28

Hm, I thought disabling output wrapper does exactly this, maybe I got the option wrong?

thheller07:08:47

I got confused by you repeating the config in :release 😛

thheller07:08:08

you need :optimizations :simple for the host build, not the bootstrap build

thheller07:08:19

FWIW since it looks like you are trying to setup a playground type thing for UIX

thheller07:08:08

maybe that can be a reference for the self host things

thheller07:08:37

although this doesn't support any npm packages, so not much help there

Roman Liutikov15:08:03

The optimizations simple setting did help, thanks. For NPM deps in bootstrapped: while requiring with module$node_modules$react_query$lib$index works in dev, in release build it's a bit weird because it still loads stuff, but I also see a bunch of errors in browser console. All of them complaining about module's default property not being a function. I guess this part (see screenshot) is how shadow rewrites NPM modules?

thheller15:08:30

not sure why it fails, this is minified closure compiler code yes

Roman Liutikov15:08:11

could it be related to the fact that shadow can handle JS modules differently via (require [some-lib :default lib]) and this somehow doesn't work in bootstrapped? just speculating here

thheller15:08:09

shouldn't affect the code generated by shadow-cljs at all

thheller15:08:27

whatever the self-hosted compiler generates I have no clue

thheller15:08:49

but no :default is just syntax sugar for :rename {default lib} basically, so it doesn't affect anything else

Roman Liutikov15:08:31

ah right, so bootstrapped cljs is just cljs itself, ok

thheller15:08:59

yes, it has no shadow-cljs mods whatsoever

👍 2
Roman Liutikov16:08:54

lol, so I'm seeing that in release build bootstrapped is loading a completely wrong module, that comes from a different NPM library not sure the cause is that I'm requiring NPM stuff as module$node_modules$react_query$lib$index or something else

thheller16:08:09

try adding :js-options {:minimize-require false} to both builds, maybe that helps

Roman Liutikov16:08:09

ha, it did help! any ideas what's happening?

thheller16:08:17

not really. :minimize-require turns of the shadow$provide[<number-here>] and instead uses the full name

thheller16:08:45

could be that the numbers don't line up between the host and bootstrap builds

👍 2
Roman Liutikov18:08:12

for this build config, can playground build have :optimizations set to :advanced? I'm not sure since bootstrapped is in separate build, but also playground depends on cljs.js

:playground {:target :browser
               :output-dir "out"
               :asset-path "/out"
               :modules {:main {:entries [uix.playground]}}
               :compiler-options {:output-wrapper false}
               :release {:compiler-options {:optimizations :simple
                                         :output-wrapper false}}}
  :bootstrap {:target :bootstrap
              :output-dir "out/bootstrap"
              :exclude #{cljs.js}
              :entries [cljs.js]
              :compiler-options {
                                 :output-wrapper false}
              :release {:compiler-options {
                                           :infer-externs true
                                           :output-wrapper false}}}

thheller18:08:01

any self-hosted involving setup cannot use :advanced no

👍 1