This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-22
Channels
- # announcements (13)
- # babashka (22)
- # beginners (22)
- # biff (17)
- # calva (6)
- # clerk (20)
- # clj-kondo (25)
- # clj-together (5)
- # clj-yaml (20)
- # cljdoc (16)
- # cljs-dev (1)
- # clojure (42)
- # clojure-brasil (1)
- # clojure-europe (26)
- # clojure-nl (6)
- # clojure-norway (24)
- # clojure-turkiye (3)
- # clojure-uk (5)
- # clojurescript (37)
- # core-async (7)
- # core-logic (2)
- # datalevin (7)
- # datomic (43)
- # events (2)
- # fulcro (7)
- # gratitude (1)
- # hyperfiddle (7)
- # java (7)
- # jobs (3)
- # lsp (4)
- # off-topic (16)
- # pathom (18)
- # polylith (1)
- # portal (27)
- # reitit (4)
- # releases (3)
- # shadow-cljs (47)
- # tools-build (14)
- # tools-deps (16)
- # yamlscript (11)
@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
still requires the same https://code.thheller.com/blog/shadow-cljs/2017/10/14/bootstrap-support.html setup
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
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?
yes. regular CLJS handles npm deps entirely differently and I have no clue how you expose it so it is found
the bootstrap target will bundle everything just fine, just not sure how you'd access it from self-host
This works in bootstrapped (require [module$node_modules$react_query$lib$index :as rq])
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"]
...
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
ah got it, maybe I can come with something hacky...
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 namespacescan't do that for self-host builds as everything needs to operate in the global scope
output-wrapper keeps the global scope clean, thus it can't find goog and whatever other namespace roots exist such as cljs
Hm, I thought disabling output wrapper does exactly this, maybe I got the option wrong?
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?
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
but no :default
is just syntax sugar for :rename {default lib}
basically, so it doesn't affect anything else
ah right, so bootstrapped cljs is just cljs itself, ok
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
ha, it did help! any ideas what's happening?
not really. :minimize-require
turns of the shadow$provide[<number-here>]
and instead uses the full name
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}}}