This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-01
Channels
- # announcements (10)
- # asami (2)
- # babashka (10)
- # beginners (55)
- # biff (37)
- # calva (9)
- # cherry (1)
- # clj-kondo (11)
- # clojure (221)
- # clojure-bay-area (12)
- # clojure-europe (77)
- # clojure-hungary (3)
- # clojure-nl (5)
- # clojure-norway (12)
- # clojurescript (11)
- # cursive (1)
- # data-science (11)
- # emacs (27)
- # figwheel (3)
- # fulcro (11)
- # graphql (5)
- # helix (7)
- # honeysql (3)
- # humbleui (9)
- # interceptors (2)
- # introduce-yourself (2)
- # kaocha (12)
- # lsp (27)
- # malli (6)
- # nbb (70)
- # off-topic (6)
- # re-frame (6)
- # react (3)
- # reitit (9)
- # releases (2)
- # scittle (29)
- # shadow-cljs (26)
- # sql (13)
- # tools-deps (61)
What am I missing here? I have a file util.cljc
:
(ns util
#?(:clj (:refer-clojure :exclude [slurp]))
#?(:cljs (:require-macros [util])))
#?(:clj
(defmacro slurp [file]
(clojure.core/slurp file)))
And a file parse.cljs
:
(ns parse
(:require [util :refer [slurp]]))
(comment
(slurp "shadow-cljs.edn")
)
Then I need to load parse.cljs
twice to use the macro:
% npx shadow-cljs node-repl
shadow-cljs - config: /Users/pez/Projects/sass2garden/shadow-cljs.edn
shadow-cljs - updating dependencies
shadow-cljs - dependencies updated
[2022-11-01 15:10:18.802 - WARNING] TCP Port 9630 in use.
[2022-11-01 15:10:18.805 - WARNING] TCP Port 9631 in use.
shadow-cljs - server version: 2.20.7 running at
shadow-cljs - nREPL server started on port 54616
cljs.user=> shadow-cljs - #4 ready!
(load-file "src/main/parse.cljs")
[]
cljs.user=> (in-ns 'parse)
nil
parse=> (slurp "shadow-cljs.edn")
Execution error (TypeError) at (<cljs repl>:1).
Cannot read properties of undefined (reading 'call')
:repl/exception!
parse=> (load-file "src/main/parse.cljs")
[]
parse=> (slurp "shadow-cljs.edn")
";; shadow-cljs configuration\n{:source-paths\n [\"src/dev\"\n \"src/main\"\n \"src/test\"]\n\n :dependencies\n []\n\n :builds\n {}}\n"
parse=>
In clojurescript you have to require macros separately using :require-macros
in the ns form https://clojurescript.org/guides/ns-forms#_macros
You're using :require-macros
in util
ns but not in the parse
ns. My guess is you just need to tweak that to use your slurp
macro
Hmmm, since I am using :require-macros
from util.cljc
, things should be good, right? It's equivalent to, util.cljs
:
(ns parse
(:require [util :refer [slurp]]))
(comment
(slurp "shadow-cljs.edn"))
+ util.clj
:
(ns util
(:refer-clojure :exclude [slurp]))
(defmacro slurp [file]
(clojure.core/slurp file))
And I get the same strange behaviour if I do it like that. Loading parse.cljs
twice makes it work.maybe you want to use this instead? https://clojureverse.org/t/using-none-code-resources-in-cljs-builds/3745
I'll try the shadow.resource way. Doesn't matter much for my current use case, but seems like something that I should be using generally.
As for the macro problem. It is quite strange. I get different results with require, but it doesn't quite work as I expect.
cljs.user=> shadow-cljs - #4 ready!
(require 'parse)
nil
cljs.user=> (parse/slurp "shadow-cljs.edn")
------ WARNING - :undeclared-var -----------------------------------------------
Resource: <eval>:1:2
Use of undeclared Var parse/slurp
--------------------------------------------------------------------------------
cljs.user=> (in-ns 'parse)
nil
parse=> (parse/slurp "shadow-cljs.edn")
------ WARNING - :undeclared-var -----------------------------------------------
Resource: <eval>:1:2
Use of undeclared Var parse/slurp
--------------------------------------------------------------------------------
parse=> (slurp "shadow-cljs.edn")
";; shadow-cljs configuration\n{:source-paths\n [\"src/dev\"\n \"src/main\"\n \"src/test\"]\n\n :dependencies\n []\n\n :builds\n {}}\n"
And trying with both qualified and non-qualified with load-file:
cljs.user=> shadow-cljs - #4 ready!
(load-file "src/main/parse.cljs")
[]
cljs.user=> (parse/slurp "shadow-cljs.edn")
------ WARNING - :undeclared-var -----------------------------------------------
Resource: <eval>:1:2
Use of undeclared Var parse/slurp
--------------------------------------------------------------------------------
cljs.user=> (in-ns 'parse)
nil
parse=> (parse/slurp "shadow-cljs.edn")
------ WARNING - :undeclared-var -----------------------------------------------
Resource: <eval>:1:2
Use of undeclared Var parse/slurp
--------------------------------------------------------------------------------
parse=> (slurp "shadow-cljs.edn")
Execution error (TypeError) at (<cljs repl>:1).
Cannot read properties of undefined (reading 'call')
:repl/exception!
parse=> (load-file "src/main/parse.cljs")
[]
parse=> (slurp "shadow-cljs.edn")
";; shadow-cljs configuration\n{:source-paths\n [\"src/dev\"\n \"src/main\"\n \"src/test\"]\n\n :dependencies\n []\n\n :builds\n {}}\n"
When writing the issue and trying to minimize it further, I notice that my repro with require
was crap. It does work with require, it is with load-file
it doesn't work. I also found out another interesting detail <- click-bait https://github.com/thheller/shadow-cljs/issues/1059
If you are targeting a :node-library
and have to use :js-provider :require
(for mariadb
since it has syntax the Closure compiler does not understand right now), is there anyway to get shadow-cljs
to import a ESM module? I tried the "https://shadow-cljs.github.io/docs/UsersGuide.html#_dynamic_module_import" section in the User Guide, but I got ReferenceError: shadow_esm_import is not defined
I guess you can also sort of make it work by adding :prepend "global.shadow_esm_import = function(s) { return import(s); };"
to your build config
I tried it, but I would have to change a quite a few things since it is a big project and I'm doing non-standard things. Many errors.
I'll try your suggestion
That worked. I added it to :target-defaults :node-library :prepend
. Thank you for your help.
Just upgraded to shadow-cljs 2.20.7
in both deps.edn and package.json. Tried to run a build report via
npx shadow-cljs run shadow.cljs.build-report client js-provider-import-report.html
and ran into the following error
File: /Users/alex/code/icebreaker/src/icebreaker/config.cljc
failed to require macro-ns "icebreaker.macros", it was required by "icebreaker.config"
Error in phase :execution
FileNotFoundException: Could not locate digest__init.class, digest.clj or digest.cljc on classpath.
so it can't find the digest
ns. This is a CLJ error, it is not from shadow-cljs. So I'm guessing you maybe don't have a deps.edn
alias activated or something like that
also note that :js-provider :import
will cause shadow-cljs to not bundle any npm dependencies. so your build report will shrink, depending on how many you used. it'll only contain cljs code after that. don't get mislead by that. the build will only work if something else provides those dependencies, so be sure to compare the final size. not the build reports.
Thanks, I'll look into the alias stuff. Our aliases haven't changed recently so I wonder if there was an underlying CLJ change that is now incompatible with our current setup
Also appreciate the tip with :js-provider :import
- that makes sense
I have cljs devtools installed with my shadow build > Installing CLJS DevTools 1.0.6 and enabling features :formatters :hints :async > But I still dont get the cljs encoded/formatted structures when i do console log. Any idea's on what i can try to get it to work?