Fork me on GitHub
#shadow-cljs
<
2019-05-22
>
rastandy08:05:21

hello everyone

rastandy08:05:57

I have a strange problem when importing an ES6 module in a cljs file.

rastandy08:05:31

when trying to call an async function from the ES6 module, the following error appears:

rastandy08:05:48

return $jscomp.asyncExecutePromiseGeneratorProgram(function($jscomp$generator$context) { ^ ReferenceError: $jscomp is not defined at Object.authClient$$module$js$oauth2 [as authClient]

rastandy08:05:26

the js module works like a charm when used by javascript code

rastandy08:05:37

I’m really stuck

Alex K15:05:21

@thheller I've been using shadow to compile a lambda for an Alexa skill, but I've hit a problem when using the juxt/tick library. It works fine with development compile, but some functions break when compiling for release. I assume something with the optimizations. Release mode does however work fine with browser target, but not with node-script/library. For all I know it could be some problem with the library, but since it worked with the browser target I figured I'd best ask here first. I put together a repro here: https://github.com/AlexSKaye/shadow-cljs-node-release-repro

thheller15:05:16

@rastandy do you require rewriting async/await code to polyfills would it be ok to assume a modern browser target?

thheller15:05:45

the error you get is from missing polyfills. not sure why they are missing but not needing them in the first place would be the easiest solution

thheller15:05:53

@noxdeleo looks like missing externs. in the browser case shadow-cljs processes all the JS and can easily generate the externs

thheller15:05:59

for not that doesn't happen so the externs are missing

thheller15:05:28

I would recommend avoiding that library ...

Alex K15:05:32

Ok, thanks.

thheller15:05:55

seriously too much code ...

thheller15:05:24

500kb for just a time lib?

thheller15:05:53

@noxdeleo you can run shadow-cljs check app to get some insights into which externs are missing

Alex K15:05:15

Wow, I didn't realise it was quite that big. Running check app gives several hundred warnings. Guess I'm hunting for another library.

thheller15:05:33

yeah check isn't super useful because of the noise it reports

thheller15:05:42

but the last few warnings are from the tick/core.cljc ns

thheller15:05:49

only those matter the rest can probably be ignored

rastandy15:05:51

@thheller thanks for your answer, I’m sorry I forgot to say that my environment is node.js v12.2.0

thheller15:05:59

so you are targeting node? not the browser?

rastandy16:05:35

@thheller yes, and I must say that wrapping not calling directly the problematic function, but calling another async function that calls the problematic one, solved the problem

rastandy16:05:45

I can share part of the code if you wish

thheller16:05:03

I'm asking because for node you can turn off the polyfill rewriting completely

thheller16:05:07

so that problem would solve itself

rastandy16:05:10

not now I’m at work but if it smells like a bug I can report

rastandy16:05:39

@thheller oh ok, I’ll check how to do that then

thheller16:05:43

just set :compiler-options {:output-feature-set :es8} or :es2018

rastandy16:05:19

trying right nonw

rastandy16:05:00

@thheller that was the problem! Thanks, and sorry for my incompetence in Javascript land

colinkahn16:05:13

Is there a way to pass -Sdeps when using :deps true?

thheller16:05:37

no, but you can bypass the shadow-cljs command if you need to

thheller16:05:50

shadow-cljs compile app is the same as clj -m shadow.cljs.devtools.cli compile app

thheller16:05:15

so clj -Sdeps ... -m shadow.... works

colinkahn16:05:25

That’s awesome, thanks!

seth18:05:52

Can anyone tell me how to get a single bundle in development? We're currently seeing 6170 files loaded, and Chrome is choking on the last couple thousand with net::ERR_INSUFFICIENT_RESOURCES. Developing a project with material-ui.

seth18:05:48

:compiler-options {:optimizations :advanced} is doing the trick for release, but seems to have no effect on dev.

raul.guajardo18:05:28

I am trying to run tests based on unit, integration, or acceptance tests. currently the namespaces look something like this

blah.bleh.integration.core-test
blah.bleh.unit.core-test
for some reason the regex is not working and all tests are being ran. Any help appreciated

raul.guajardo14:05:02

BUMPING: since apparently we don't use threads

seth19:05:18

Update to my above question, :loader-mode :eval seems to have done the trick, as per: https://clojureverse.org/t/any-chance-we-could-reduce-the-bundle-size-in-development/3690/2

thheller19:05:05

@satwood how do you get to 6k files? that seems like a lot 😛

seth20:05:09

@thheller Yes, it is a lot! 😆 This is how:

(:require [reagent.core :as r :refer [atom]]
           ["@material-ui/core" :as mui]
           ["@material-ui/core/styles" :refer [createMuiTheme]]
           ["@material-ui/core/colors" :as mui-colors]
           ["@material-ui/styles" :as mui-styles]
           ["@material-ui/icons" :as mui-icons]
           ["@material-ui/system" :as mui-system])

seth20:05:56

Thank you for the link to the original article! 🙌

thheller20:05:10

yeah you definitely should try to reduce it to the things you actually use

thheller20:05:16

otherwise your build is going to be gigantic

hlolli20:05:55

think it's possible to connect to a shadow-cljs repl with npm-module target on react-native platform?

thheller20:05:21

sure, its what the :react-native target does

hlolli20:05:54

so npm-module is unneccecary?

thheller20:05:24

depends. is everything CLJS or do you have existing JS and want to include some CLJS?

hlolli20:05:51

I'm testing Haul, so I need webpack compatability

thheller20:05:31

hmm so you have a manual index.js or so?

thheller20:05:39

thats used as the haul entrypoint?

hlolli20:05:49

yes I have index.js

hlolli20:05:05

that's webpack's entry, and some hmr patches

thheller20:05:11

in the index.js you require("./foo/your.app")?

thheller20:05:54

ok in the file you can add something like if (process.env.NODE_ENV == "development") { require("./foo/shadow.cljs.devtools.client.react-native"); }

thheller20:05:02

and in your build config set :runtime :react-native

hlolli20:05:40

ah ! I see it now, I did set the :react-native runtime

hlolli20:05:55

but now finally see that devtool file, only saw env, hud and browser

thheller20:05:20

:npm-module just doesn't have clearly defined entries so it can't add :preloads

thheller20:05:57

preloads still cause the code to be compiled

thheller20:05:01

you just have to load it yourself

hlolli20:05:13

yes, looks like an easy workaround to me

thheller20:05:34

you can try using the :react-native target btw

thheller20:05:47

that takes care of all of this and should be loadable by haul

hlolli20:05:10

yes, if I can drop the hmr for shadow's reload, it would make sense

thheller20:05:11

(it uses :npm-module in development)

hlolli20:05:23

which I should

thheller20:05:43

I don't know what special hooks haul requires

thheller20:05:02

but the react-native target is basically just an :npm-module build with a generated index.js

hlolli20:05:16

yes that sounds about the same with haul

thheller20:05:16

so you can either use that index.js directly

thheller20:05:43

or create a dedicated index.js for haul and require("./foo/index.js") from there

hlolli20:05:09

I'll try that now, requireing that devtool doesn't make shadow detect an environment, but that could be my side...

thheller20:05:28

not sure what you mean by that

hlolli20:05:56

shadow.user> (shadow.cljs.devtools.api/nrepl-select :app)
To quit, type: :cljs/quit
[:selected :app]
cljs.user> :a
REPL command timed out.
cljs.user> :a
REPL command timed out.
it connects, but times out, never actually used the nrepl with metro/vanilla-react-native so I don't know what to expect 🙂

thheller20:05:18

that might be for a variety of reasons

thheller20:05:29

check the react native log

thheller20:05:40

react-native log-ios or whatever that command was called

thheller20:05:14

REPL should be working normally but I have no clue what you are doing to the code 😉

hlolli20:05:38

2019-05-22 20:35:35.535 10517-11493/com.hlolli W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTDeviceEventEmitter.emit(["websocketMessage",{"data":"{:type :repl/invoke, :name \"<eval>\", :js \"new cljs.core.Keyword(null,\\\"a\\\",\\\"a\\\",-2123407586)\", :source \":a\", :source-map-json \"{\\\"version\\\":3,\\n \\\"file\\\":\\\"<eval>\\\",\\n \\\"sources\\\":[\\\"<eval>\\\"],\\n \\\"lineCount\\\":1,\\n \\\"mappings\\\":\\\"\\\",\\n \\\"names\\\":[],\\n \\\"sourcesContent\\\":[\\\":a\\\"]}\\n\", :warnings [], :id 2}","type":"text","id":2}])

thheller20:05:03

absolutely no clue what that means 😛

hlolli20:05:19

ok at least there's a clue, Sherlock Holmes mode on

hlolli20:05:45

just a restart and now it works

hlolli20:05:10

it happens tough after every hot module reload, then the context which shadow is connected to is destroyed and new one is made

hlolli20:05:33

could I have the HMR reload some js file to sync it? like that devtools file?

thheller20:05:07

by HMR you mean something haul does? because you should absolutely disable anything reloading related that haul does

hlolli20:05:20

no that's an opt-in

hlolli20:05:23

I can turn it off

hlolli20:05:31

I'll do that now 🙂

hlolli21:05:56

giving up on Haul. Better than Metro, but only by a margin. Better to use their server code and push shadow-cljs code directly from a bundle into a emulator/device. Not sure how much work that would be.