Hi! Is there any documentation / articles about usage of :js-options {:babel-preset-config { ... }}
? I'm trying to enable polyfills for IE11.
this only affects npm packages that are actually transpiled by babel. which is only a very small percentage. so much so that this option is mostly useless.
what kind of polyfills is it not detecting already? this is usually controlled by setting :compiler-options {:output-feature-set :es5}
(which is the default)
you can try :es3
Oh, I see. Looks like I should be using :compiler-options
, instead of :babel-preset-config
, because my project probably don't have such npm packages. Thanks for your answer, I'll try it.
also note that watch/compile builds may not work in IE11 regardless of polyfill status
best to test that with release
only
Got it, thanks!
Hello, everyone! I'm having a go at spinning up a Lambda function with Clojurescript via Shadow CLJS, and I'm running into a strange error that returns three results via Google. 🙂
$ yarn run shadow-cljs compile lambda --verbose
shadow-cljs - config: /home/jcf/code/example/shadow-cljs.edn
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
[:lambda] Compiling ...
-> build target: :node-library stage: :configure
<- build target: :node-library stage: :configure (3 ms)
-> Resolving Module: :main
With both release
and compile
I get this error after the output above:
The required namespace "example.lambda" is not available, it was required by "shadow/umd_helper.cljs".
I've found a GitHub issue related to generating single files, with a recommendation to use ncc
to package everything into a single file, which I can do as soon as I have something compiling.
My build looks like this:
{:builds
{:lambda
{:deps {:aliases [:lambda]}
:output-to "amplify/backend/function/example/src/index.js"
:target :node-library
:exports {:handler example.lambda/handler}
:devtools {:enabled false}
:compiler-options {:infer-externs :auto
:source-map true}}}}
I've triple checked the namespace and path to my namespace and it's very correct (I've copied and pasted the name back and forth to be doubly sure).In my deps.edn
I have an alias that sets :paths ["src"]
…
If anyone has a working example of generating a :node-library
that I can package up with ncc
I'd be extremely grateful.
Definitely scratching my head on this one. :thinking_face:
Relevant links above, with two archived Slack convos coming right up…
https://clojurians-log.clojureverse.org/shadow-cljs/2018-06-26
https://clojurians-log.clojureverse.org/clojurescript/2020-09-04
I think tomorrow I might create a little repo to see if I can reproduce outside of my codebase. If so, I can open a decent issue on GitHub.
Hello, for my information, why do you build a "node-library" and not a "node-script" or "esm" (https://clojureverse.org/t/generating-es-modules-browser-deno/6116)? Moreover, shadow-cljs will generate one js file: why do you need ncc for?
@mandimby.raveloarinja see this GitHub issue and its conclusion: https://github.com/thheller/shadow-cljs/issues/290#issuecomment-539087352
@jcf the file is supposed to be /home/jcf/code/example/src/example/lambda.cljs
. make sure it actually exists. the :deps
inside :builds
is incorrect. it is supposed to be at the top level
it doesn't matter if you have rum on the classpath or not for other code
if it isn't explicitely required in any of your code it won't be used
so the lambda isn't affected at all whether its on the classpath or not
can't see your :paths
though
assuming :paths ["src"]
in deps.edn
is set correctly
indeed I just did a small test. The target "node-lib" needs the node_modules to be bundled with the js; The target "esm" bundles everything in one js natively. However, the version of node on lambda is node 12 that does not support esm without the flag "--experimental-modules" (http://2ality.com/2019/04/nodejs-esm-impl.html#using-es-modules-on-nodejs)
I wasn’t sure if :deps
could be nested. I want to use different dependencies for different builds, and went for :aliases
…
I think I’ve done all of the above, but will double check after a good night’s rest. Thanks, thheller. 🙇
this is not supported and also usually quite useless. see https://code.thheller.com/blog/shadow-cljs/2018/02/08/problem-solved-source-paths.html
Is that post related to isolating dependencies declared using tools.deps’ :deps
or is it to do with source paths (e.g. src/cljs
)?
I was trying to include a different set of third-party dependencies (my Lambda doesn’t need Rum) and have all my Clojure-like source collocated.
I’ll have a proper read in the morning to make sure I’m understanding it. Thanks, thheller! You’re work as always is appreciated. 🙇
Is there an issue with shadow and macros, perhaps in the context of .cljc? I define…
(defmacro deftags [& tags]
`(do ~@(for [tag tags]
`(deftag ~tag))))
…in one NS, require it in another,
(ns mxweb.tag
(:require
[mxweb.gen :as gen]))
(gen/deftags a abbr acronym ...etc..)
…then a check
reports
------ WARNING #1 - :undeclared-var --------------------------------------------
Resource: mxweb/tag.cljc:5:2
Use of undeclared Var mxweb.gen/deftags
A conventional CLJS build using the lein meis
scripts works OK. Thx!Did you include require-macros :refer [deftags] in cljc file?
@hiskennyness https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html most likely your are missing the :require-macros
in the mxweb.gen
ns for itself
@karol.wojcik I started with :require-macros
in the using mxweb.tag
NS and was seeing the same error. Thx to @thheller’s blog post I see the linkage is a bit hairier than I realized and will give it another go. btw, I had everything in .cljc
s, and will start by moving macros into a .clj
just to reduce the unknowns.
You should have put it in mxweb.gen
Yeah, that was the shocker I picked up from @thheller’s blog. I did all this years ago using the mies
scripts. That worked OK, but I am curious about Shadow. One puzzle is that I do not have the macros in a .clj
, which I do remember as a requirement! I guess the .cljc
gives me the .clj
compile for the macros? Anyway, I plan to KISS and move the macros into a .clj
, then set things up as you have described. Thx!
.cljc
as far as CLJS macros are concerned are just two files in one. one for CLJ one for CLJS. the macro rules are exactly the same but IMHO it is much easier to follow those rules with two actual files instead of one
Yeah, I am splitting them up now. This will be a challenge for any tooling, tho: deftag
generates a macro. 🙂 Results shortly…
Works like a charm. Thx @karol.wojcik and @thheller!