This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-26
Channels
- # announcements (1)
- # autochrome-github (1)
- # babashka (9)
- # beginners (112)
- # bristol-clojurians (2)
- # calva (26)
- # cider (10)
- # clj-kondo (31)
- # cljs-dev (40)
- # clojure (114)
- # clojure-austin (1)
- # clojure-dev (112)
- # clojure-europe (22)
- # clojure-germany (5)
- # clojure-italy (1)
- # clojure-nl (2)
- # clojure-norway (1)
- # clojure-spec (10)
- # clojure-uk (96)
- # clojurescript (39)
- # core-logic (5)
- # datomic (40)
- # fulcro (34)
- # graphql (17)
- # jobs (3)
- # kaocha (4)
- # leiningen (10)
- # luminus (1)
- # malli (3)
- # meander (44)
- # midje (2)
- # off-topic (40)
- # pathom (5)
- # re-frame (8)
- # reitit (8)
- # ring (3)
- # ring-swagger (4)
- # shadow-cljs (83)
- # spacemacs (96)
- # tools-deps (16)
- # vim (4)
- # xtdb (15)
- # yada (20)
@thheller, that solved the problem Thank you so much. On my deps.edn, I added the following:
org.clojure/clojurescript {:mvn/version "1.10.597"
:exclusions
[com.google.javascript/closure-compiler-unshaded
org.clojure/google-closure-library
org.clojure/google-closure-library-third-party]}
com.google.javascript/closure-compiler-unshaded {:mvn/version "v20191027"}
org.clojure/google-closure-library {:mvn/version "0.0-20191016-6ae1f72f"
:scope "provided"}
org.clojure/google-closure-library-third-party {:mvn/version "0.0-20191016-6ae1f72f"}
is it possible that the build generated by shadow-cljs release
can include different versions of npm libs than the one generated by shadow-cljs watch
? (it sounds impossible just writing it 😅 but want to be sure as i'm having a weird bug between in my release build, and it's not a typical extern missing bug, more like a js library outdated and thus returning an error)
yeah that makes sense :thumbsup:
like i get this error (when sending a eth transaction) with the release bundle and nothing with the dev bundle
and it seems it's because the "value" i'm passing is a BigNumber and the library (encoding parameter for the eth transaction) should accept it, which it does in dev but not in release mode
but could be then the dynamic require issue
i finally understand what is going on:
the js library has a function to check if an object is a BigNumber, it does so by getting object.constructor.name
which returns "BigNumber" in dev but a u
in prod, because i'm requiring the bignumber.js
lib in one of my cljs file it gets optimized.
can i fix that with this method? https://shadow-cljs.github.io/docs/UsersGuide.html#_simplified_externs
you can also turn off the renaming completely via :js-options {:property-renaming :off}
ah nice didn't know about that ! if i use the externs/app.txt i go with just the line "BigNumber" or i need smth different because it's a constructor?
it doesn't seem to be working when i write :
# externs/app.txt
BigNumber
😄 yeah it's not ideal https://github.com/ethereum/web3.js/blob/1.x/packages/web3-utils/src/utils.js#L50-L52
can i type hint smth here?
(ns my-ns
(:require ["bignumber.js" :as BigNumber]))
(defn to-big-number [num]
(BigNumber num))
I'm not actually sure the extrerns are applied at all to node_modules dependencies. usually they don't need any since they only run through :simple
it works! thanks :thumbsup: hopefully it doesn't increase the size of the bundle too much 🙂
fyi (in terms of bundle size) before:
and after:
maybe you should try to find out why the eth lib doens't just use instanceof
? seems rather weird to me to be checking a name
yeah good point
i think it's because they're not including the actual BigNumber package
but looking a bit further they're only calling isBigNumber
once so i can find a work-around in my code :thumbsup:
or i could rewrite this js function in my code no https://github.com/ethereum/web3.js/blob/e914ec3bf1ae3bd053ab86959c001280a2ea79f2/packages/web3-eth-abi/src/index.js#L99 ?
maybe too complex - i'll just go with the workaround 🙂
i found that overriding the isBigNumber
method seems to be working as well 🤓
@thheller Not sure if you remember but I’ve had some issues with source maps for node-library
and node-script
. After I earlier thought that everything is actually working I now created a repro case that exhibits the same problems I’m seeing in a larger code base: https://github.com/martinklepsch/shadow-cljs-broken-node-source-maps
Let me know if this is helpful, if there’s any more things that should be tested before considering this a bug
No particular reason but verified similar behavior when not setting a custom :optimizations
value
Will also give :whitespace
a try
yup, just saw that 😅
I think it might be an artifact from before using shadow
it seems to be working ok-ish for me with :advanced
. it just moving code all over the place so the actual source-maps.core
ns/file doesn't exist anymore since its just inline elsewhere
let me try with advanced in a more complex codebase
Seeing similarly off results with :advanced
$ node -r source-map-support/register out/main.js 0
Error: boom
at new $cljs$core$ExceptionInfo$$ (/mnt/c/Users/thheller/code/tmp/shadow-cljs-broken-node-source-maps/out/cljs/core.cljs:11304:31)
at Function.<anonymous> (/mnt/c/Users/thheller/code/tmp/shadow-cljs-broken-node-source-maps/out/source_maps/core.cljs:4:9)
at $cljs$core$apply_to_simple$cljs$0core$0IFn$0_invoke$0arity$03$$ (/mnt/c/Users/thheller/code/tmp/shadow-cljs-broken-node-source-maps/out/cljs/core.cljs:3890:15)
at $cljs$core$apply$cljs$0core$0IFn$0_invoke$0arity$02$$ (/mnt/c/Users/thheller/code/tmp/shadow-cljs-broken-node-source-maps/out/cljs/core.cljs:3924:30)
at /mnt/c/Users/thheller/code/tmp/shadow-cljs-broken-node-source-maps/out/cljs/core.cljs:10028:46
at Object.<anonymous> (/mnt/c/Users/thheller/code/tmp/shadow-cljs-broken-node-source-maps/out/main.js:5698:3)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
(ns source-maps.core)
(defn main [x]
(when (zero? (js/parseInt x 10))
(throw (ex-info "boom" {:x x}))))
{:deps true
:builds
{:main
{:target :node-script
:main source-maps.core/main
:output-to "out/main.js"
:compiler-options {:source-map true}}}}
Like sourcemap.clj
returns lines in cljs-node-io.core
as part of the stacktrace but the error is thrown elsewhere
you mean release --debug
?
what is source-map-support/register
?
Ah interesting, so that allows us to see source maps right in the stacktrace vs using sourcemap.clj
? that’s convenient 😅
yeah for development builds thats just loaded automatically. for release you have to load it
Ok, I can reproduce --debug
fixing the issue
interesting, it seems like after installing source-map-support I get more reasonable mappings already
also when looking them up with sourcemap.clj
so I suspect source maps work better because of pseudo-names giving everything names that would otherwise be stripped
after a few more hours of fiddling with this I find that the only way I can remotely make it work is optimizations simple + pseudo-names
and pretty-print
but also there’s so many variables that I’m losing trust that I can actually hold the different combinations in my head 😄
hmm yeah I dunno why its so weird, I don't do much node stuff so I can't really tell where the problem is
I’ve tried setting pseudo-names
and pretty-print
individually but I’ll give --debug
another try as well
--pseudo-names
is pseudo and pretty because sometimes its easier to debug without source maps
I'm troubleshooting an issue in IE11 - my compiled app throws the error "WeakSet is undefined." I did npm install --save weakset
and included ["weakset"]
in my top-level require, but I'm still getting the error. Do I need to explicitly set js/window.WeakSet
? Declare an extern? The user guide says that everything should be polyfilled down to IE10+, but I think I must be taking that out of context or something. Thanks!
(ns multicare-dfd.core
(:require
["weakset"]
[reagent.core :as reagent] ,,, ))
@ctamayo who/what uses weakset? for polyfills like that it is probably better to use a third party polyfill since modern browsers won't need it
something like https://polyfill.io/v3/
@thheller I'm not actually sure what is using it. I'm a bit confused because npm ls weakset
just shows that my top-level module is the thing including it. What do you mean by polyfills like that?
so if its not your code using weakset then it is likely some library which assumes you are using a modern browser or polyfills
so then I am misunderstanding this somehow: > By default the generated JS output will be compatible with ES5 and all "newer" features will be transpiled to compatible code using polyfills. This is currently the safest default and supports most browsers in active use (including IE10+). What does that mean, if not that shadow-cljs injects polyfills needed for IE10+? Based on what you're saying I'd expect WeakSet to fall under that umbrella
i finally understand what is going on:
the js library has a function to check if an object is a BigNumber, it does so by getting object.constructor.name
which returns "BigNumber" in dev but a u
in prod, because i'm requiring the bignumber.js
lib in one of my cljs file it gets optimized.
can i fix that with this method? https://shadow-cljs.github.io/docs/UsersGuide.html#_simplified_externs