This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-01
Channels
- # aleph (2)
- # announcements (3)
- # architecture (9)
- # babashka (56)
- # beginners (18)
- # calva (7)
- # catalyst (16)
- # cider (18)
- # cljfx (3)
- # cljs-dev (23)
- # clojure-europe (11)
- # clojure-hungary (1)
- # clojure-nl (2)
- # clojure-norway (24)
- # clojure-sweden (2)
- # clojurescript (37)
- # code-reviews (47)
- # datalog (3)
- # datomic (8)
- # emacs (11)
- # events (2)
- # graalvm (7)
- # gratitude (1)
- # hyperfiddle (12)
- # java (1)
- # jvm (46)
- # kaocha (3)
- # lsp (3)
- # malli (4)
- # matcher-combinators (1)
- # music (1)
- # nbb (1)
- # nrepl (4)
- # releases (1)
- # sci (15)
- # shadow-cljs (21)
- # slack-help (21)
- # tools-deps (17)
I ran into a strange situation with this module: https://github.com/dankogai/js-base64
I am using it like this:
["js-base64" :refer [Base64]]
and then
(Base64.encode jsonstring)
which works great in local development mode, but in production the following error happens:
2023-09-01 01:00:21 TypeError: Cannot read properties of undefined (reading 'encode')
When I do a (js/console.log Base64)
in prod it prints as null. The module files exist in node_modules
and are identical to my local.works fine for me. FWIW you should stick to proper interop when working with JS libs, this nested dot stuff is known to cause problems with inference and stuff. encode
in this case is safe from renaming though, so I'm not sure what the problem would be. (Base64.encode ...)
should be proper (.encode Base64 ...)
Ok I will try to take another look at why this happened since it works fine for you. Thanks for checking.
I also tried importing encode
directly using [js-base64$Base64" :refer [encode]]
and in that situation encode
is null on prod.
Prod is compiled like this: npx shadow-cljs release server --debug
and the shadow-cljs.edn
looks like this:
:builds {:server {:target :node-script
:output-to "devserver.js"
:main ytt.server/main!
:release {:output-to "build/server.js"}}
In the end I have used a different library but I thought I'd report this here in case it helps.
FWIW google closure library already comes with a base64 encoderā¦ so you get it āfor freeā with CLJS
with that said, I assume the issue with your node script is that optimizations are set to advanced and base64 library doesnt play nicely with it
I have ran into issues with the :node-script
target where library code presumably gets mixed with the emitted JS output of ClojureScript, so you are forced into using simple optimizations or else you run into problems like youve described
Oh I should have thought of using the closure lib, thanks!
with that said, I recommend testing use of the npm base64 library with optimizations set to simple
yes, your JS file will be huge, but it should work.. and if it does work, then you will have a faster base64 codec, since the base64
package on npm actually uses a native library to handle encode and decode
For this particular project that's probably premature optimization (I am making a beeline towards shipping so I can get back to other things, and it's fast enough with the new library). That's a great point though, thanks!
I believe this may be referencing a dead link:
WARNING: shadow-cljs not installed in project.
See
using shadow {:mvn/version "2.25.2"}
indeed. I'll be removing that message entirely soon, so no use in documenting it now š
it is also complaining about the npm package not being installed, no the deps.edn one
Can shadow install ClojureScript dependencies from git tag?
correct, just use deps.edn https://shadow-cljs.github.io/docs/UsersGuide.html#deps-edn
perfect, thanks!