Fork me on GitHub
#shadow-cljs
<
2020-10-07
>
jahson09:10:42

Hi! Is there any documentation / articles about usage of :js-options {:babel-preset-config { ... }}? I'm trying to enable polyfills for IE11.

thheller10:10:48

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.

thheller10:10:41

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)

thheller10:10:45

you can try :es3

jahson10:10:54

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.

thheller10:10:13

also note that watch/compile builds may not work in IE11 regardless of polyfill status

thheller10:10:21

best to test that with release only

jahson11:10:52

Got it, thanks!

jcf16:10:43

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).

jcf16:10:13

In my deps.edn I have an alias that sets :paths ["src"]

jcf16:10:37

If anyone has a working example of generating a :node-library that I can package up with ncc I'd be extremely grateful.

jcf16:10:54

Definitely scratching my head on this one. :thinking_face:

jcf17:10:21

Relevant links above, with two archived Slack convos coming right up…

jcf17:10:41

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.

Mandimby Raveloarinjaka18:10:18

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 Raveloarinjaka20:10:20

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)

👍 3
thheller20:10:03

@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

jcf21:10:05

I wasn’t sure if :deps could be nested. I want to use different dependencies for different builds, and went for :aliases

jcf21:10:22

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.

jcf21:10:46

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. 🙇

thheller07:10:45

it doesn't matter if you have rum on the classpath or not for other code

thheller07:10:55

if it isn't explicitely required in any of your code it won't be used

thheller07:10:06

so the lambda isn't affected at all whether its on the classpath or not

👍 3
thheller20:10:38

can't see your :paths though

thheller20:10:58

assuming :paths ["src"] in deps.edn is set correctly

3
jcf21:10:13

I think I’ve done all of the above, but will double check after a good night’s rest. Thanks, thheller. 🙇

kennytilton23:10:48

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!

Karol Wójcik07:10:19

Did you include require-macros :refer [deftags] in cljc file?

thheller07:10:38

@U0PUGPSFR 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

kennytilton08:10:36

@UJ1339K2B I started with :require-macros in the using mxweb.tag NS and was seeing the same error. Thx to @U05224H0W’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 .cljcs, and will start by moving macros into a .clj just to reduce the unknowns.

Karol Wójcik10:10:46

You should have put it in mxweb.gen

kennytilton15:10:38

Yeah, that was the shocker I picked up from @U05224H0W’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!

thheller15:10:00

.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

kennytilton15:10:15

Yeah, I am splitting them up now. This will be a challenge for any tooling, tho: deftag generates a macro. 🙂 Results shortly…

kennytilton16:10:13

Works like a charm. Thx @UJ1339K2B and @U05224H0W!

🎉 6