This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-19
Channels
- # announcements (2)
- # beginners (12)
- # cider (12)
- # cljsrn (1)
- # clojure (56)
- # clojure-italy (1)
- # clojure-sweden (2)
- # clojure-uk (3)
- # clojured (6)
- # clojurescript (16)
- # cursive (1)
- # data-science (3)
- # datomic (8)
- # emacs (18)
- # figwheel-main (1)
- # graphql (5)
- # jobs (10)
- # luminus (4)
- # nrepl (27)
- # off-topic (5)
- # pathom (7)
- # shadow-cljs (66)
- # sql (40)
- # tools-deps (1)
- # vim (6)
I'm seeing a problem with my release build where the transpiled version of goog.string/format
isn't making it into the build
@mattly it's not by any chance that one needs to require goog.string.format in order to use goog.string, right? (cf. text starting "Sometimes" at: https://clojurescript.org/reference/google-closure-library#requiring-a-function)
it seems like it would, yes. there is theory and there is practice though, sometimes 🙂
and the compiler that this is the standard library for isn't smart enough to know that?
@mattly the namespace structure in the closure library isn't very strict so sometimes a singular function is split into a separate "namespace" which actually is just a function. so sometimes it doesn't map cleanly to the CLJS namespacess. goog.string.format
is an actual "provided name" which you require via (:require [goog.string.format])
but since it isn't an actual namespace we have to use it via (:require [goog.string.format] [goog.string :as gstr]))
(gstr/format ...)
Hi, I am trying to get Hello world Web Worker example working from the guide, but I am getting a mysterious runtime error. My shadow-cljs.edn configuration:
{:target :browser
:output-dir "resources/public/js/compiled"
:asset-path "/js/compiled"
:modules {:main {:entries [orgpad.client.core]
:init-fn orgpad.client.core/init}
:layout {:entries [orgpad.client.layout.webworker.core]
:depends-on #{:main}
:web-worker true}}
:compiler-options {:infer-externs :auto}
:devtools {:after-load orgpad.client.core/mount-root
:watch-dir "resources/public"}}
The code in orgpad.client.core/init:
(let [layout (js/Worker. "/js/compiled/layout.js")]
(.addEventListener layout "message" (fn [e] (js/console.log "Layout message recieved:" e)))
(.postMessage layout "Hello World!"))
The Web Worker code:
(ns orgpad.client.layout.webworker.core)
(js/self.addEventListener
"message"
(fn [^js e]
(js/postMessage (.-data e))))
The runtime error:
Uncaught ReferenceError: Node is not defined
at Object.hickory$core$node_type [as node_type] (core.cljs:37)
at core.cljs:39
at layout.js:2937
at Array.forEach (<anonymous>)
at Object.env.load (layout.js:2933)
at layout.js:2969
to the line (aget js/Node (str type "_NODE")))
where js/Node is not known. It points to one of my dependencies [hickory "0.7.1"], not used in Web Worker at all.you use :depends-on #{:main}
which means all the code from :main
will be loaded in the worker
:modules {:shared {:entries []}
:main {:init-fn orgpad.client.core/init
:depends-on #{:shared}}
:layout {:entries [orgpad.client.layout.webworker.core]
:depends-on #{:shared}
:web-worker true}}
you can leave :entries
empty for shared which means all code used in both :main
and :layout
will be moved there
Now i get: Uncaught ReferenceError: SHADOW_ENV is not defined at main.js:1
No, how should I load it?
heya, should shadow-cljs watch test
with a config such as
{...
:builds
{:test
{:target :node-test
:output-to "out/node-tests.js"
:ns-regexp "-spec$"
:autorun true}}}
run the tests on every rebuild?I see shadow-cljs compile test
building and running the tests, but shadow-cljs watch test
only seems to build and rebuild, but not run them
the output may be routed incorrectly if you have a shadow-cljs server
(or other watch
) running elsewhere
ah that was it!
it was a bit unexpected to me, is it a bug or the intended behaviour?
bug I guess. watch runs in a different thread that doesn't capture the *out*/*err*
bindings, so it'll use the default of the server
I could see it going both ways really, depending on what the intended experience is (watch the server console or watch the command console)
feel free to open an issue. I'm stuck behind something else so can't fix that right now
no urgency in this really, but I'll open an issue for it to be recorded
turns out there's a good one already: https://github.com/thheller/shadow-cljs/issues/487
I have set :before-load and :after-load functions to restart the Web worker. It works fine when I do changes in the code outside of Web worker, but it does not reload correcly when I just update WW code. I have even tried to reload it via Shadow-cjls REPL.
Devtools are set as follows:
:devtools {:after-load orgpad.client.core/mount-root
:before-load orgpad.client.core/stop-web-workers
:watch-dir "resources/public"}
it displays the shadow-cljs icon when changing WW code and it detects errors, but no reloading occurs
@pavel.klavik what does the browser console say?
nothing
@pavel.klavik do you maybe have the console filtering too much? it should be showing something?
https://code.thheller.com/blog/shadow-cljs/2019/08/25/hot-reload-in-clojurescript.html maybe this helps?
no filtering, normally it displays shadow-cljs: load JS ..... shadow.cljs.devtools.client.browser.js:48 shadow-cljs: call orgpad.client.core/mount-root
I will take a look at the link but I am not likely doing anything strange
This is the full shadow-cljs.edn:
{:source-paths ["src"]
:dependencies [[reagent "0.8.1"]
[reagent-utils "0.3.3"]
[re-frame "0.10.6"]
[day8.re-frame/http-fx "0.1.6"]
[hickory "0.7.1"]
[binaryage/devtools "0.9.10"]
[bidi "2.1.5"]
[com.taoensso/sente "1.14.0-RC2"]
[venantius/accountant "0.2.4"]
[com.cemerick/url "0.1.1"]]
:nrepl {:port 9000}
:builds {:client {:target :browser
:output-dir "resources/public/js/compiled"
:asset-path "/js/compiled"
:modules {:shared {:entries []}
:main {:init-fn orgpad.client.core/init
:depends-on #{:shared}}
:layout {:entries [orgpad.client.layout.webworker.core]
:depends-on #{:shared}
:web-worker true}}
:compiler-options {:infer-externs :auto}
:devtools {:after-load orgpad.client.core/mount-root
:before-load orgpad.client.core/stop-web-workers
:watch-dir "resources/public"}}}}
isn't the problem that the Web worker namespaces are not detected as part of the main app, so not reloaded?
the changes are propagated, so if I modify WW and then modify the app code, everything gets reloaded and WW is updated as well
Hi, I am trying to include the zenroom npm package that uses a wasm file in shadow-cljs. There’s an example blogpost (https://www.dyne.org/using-zenroom-with-javascript-react-part3/) on how to use the library in React, where it’s described to put the .wasm file in the public folder so it’s served on /zenroom.wasm. Also some code needs to be changed so that the javascript wrapper looks for the wasm in that path, and does not try to find it locally. I did the same steps, but I get the error >failed to load zenroom_example.views.js TypeError: “C.then is not a function” This code comes from the wrapper.js:
require("core-js/stable");
require("regenerator-runtime/runtime");
var _zenroom = _interopRequireDefault(require("../dist/lib/zenroom.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var C = (0, _zenroom.default)();
Which loads some file via a relative path. It might be the case that this does not work with shadow-cljs?
I had to include the npm packages core-js and regenerator-runtime in the packages.json before I got to this error.
I noticed that shadow-cljs minifies all the npm packages and serves it under for example /js/compiled/cljs-runtime/module$node_modules$zenroom$dist$wrapper.js. So just to be sure I also served the wasm under js/compiled/cljs-runtime/zenroom.wasm, but that does not change anything.
Is this problem related to the wasm not compiling? Or due to the relative path?
I changed the relative path loading to _interopRequireDefault(require("/js/compiled/cljs-runtime/module$node_modules$zenroom$dist$lib$zenroom.js"));
but that did not fix hte problem.
Can anybody help me include this package with wasm and require
s?
Full source code is at: https://github.com/transducer/zenroom-example@erwinrooijakkers that repo contains no sources to look at
Oops src was in gitignore for some reason
Removed it 🙂
It works!!!
wasm to resources and changing what was said in the blogpost was enough
It works now so not necessary to look into it. Thanks for all the support!