Fork me on GitHub
#shadow-cljs
<
2019-04-10
>
wilkerlucio00:04:34

@d4hines you could also use (gobj/set (.getElementById js/document "fps") "innerHtml" (str "<p>" n "<p>"))

wilkerlucio00:04:56

gobj => goog.object

thheller08:04:39

@lilactown @wilkerlucio can you confirm that .shadow-cljs is a git ignored directory in your projects? just a guess but maybe git messes with the .shadow-cljs dir when switching branches? probably not but who knows šŸ˜›

wilkerlucio11:04:20

@thheller yup, its confirmed, and in my case I wasn't switching branches, just the shadow-cljs version

rastandy12:04:55

hello @thheller, Iā€™m sorry to bother you again but my js file importing adventure is not finished yet

rastandy12:04:46

now it seems that everything works if I call functions from the js file that do not depends on imported modules

rastandy12:04:21

but when I use a more complex function with external dependencies the compiler complains like in this case:

rastandy12:04:57

node target/main.js SHADOW import error /Users/arusso/Development/clojurescript/ask-scopus/.shadow-cljs/builds/app/dev/out/cljs-runtime/server.google_sheet.js /Users/arusso/Development/clojurescript/ask-scopus/.shadow-cljs/builds/app/dev/out/cljs-runtime/server/oauth2.js:17 fs.readFile(ā€˜credentials.jsonā€™, (err, content) => { ^ TypeError: fs.readFile is not a function at Object.readFile [as auth_init] (/Users/arusso/Development/clojurescript/ask-scopus/.shadow-cljs/builds/app/dev/out/cljs-runtime/server/oauth2.js:17:5) at /Users/arusso/Development/clojurescript/ask-scopus/.shadow-cljs/builds/app/dev/out/cljs-runtime/server/google_sheet.cljs:8:1 at global.SHADOW_IMPORT (/Users/arusso/Development/clojurescript/ask-scopus/target/main.js:64:44) at /Users/arusso/Development/clojurescript/ask-scopus/target/main.js:2195:1 at Object.<anonymous> (/Users/arusso/Development/clojurescript/ask-scopus/target/main.js:2199:3) at Module._compile (internal/modules/cjs/loader.js:805:30)

rastandy12:04:44

obviously I have the const fs = require(ā€˜fsā€™); in the js file

rastandy12:04:02

and the [ā€œ./oauth2ā€ :as auth] in the clojurescript namespace. In fact an dependency-free hello-world function from the js file is correctly imported and called from the CLJS namespace.

thheller12:04:14

@rastandy and what is console.log(fs) in the oauth2.js file?

rastandy12:04:00

@thheller well, itā€™s {}

rastandy12:04:28

but if I call ā€œnode src/oauth2.jsā€ it works

thheller12:04:57

that doesn't mean anything

thheller12:04:05

the commonjs support is sketchy

rastandy12:04:09

@thheller I mean that the import is correct in the js file

rastandy12:04:47

@thheller so you suggested me to use another module system?

thheller12:04:51

yes but that is irrelevant. shadow-cljs just fails to rewrite the require properly

thheller12:04:07

ESM support should be a bit better yes

thheller12:04:18

I can see about the commonjs require later, busy with other stuff currently

rastandy13:04:02

@thheller can you point me to some docs to convert my js file to ESM and import it correctly in CLJS? Sorry Iā€™m pretty ignorant in JavaScript modules land

thheller13:04:29

just plain ESM, nothing special regarding CLJS

thheller13:04:45

and no I don't have a guide handy.

rastandy13:04:47

@thheller I can only thank you for your help and support, thank you very much!

rastandy13:04:07

@thheller Iā€™ll find one, many thanks

rastandy13:04:18

@thheller great! Converting in ESM module everything works! Many, many thanks.

Francesco14:04:56

hello, I am struggling with shadow-cljs and hope you could help me (or point me somewhere), is there any way to run browsers tests (or karma test) in watch mode? (to be more explicit, re-run affected tests only whenever something changes in the code/tests)

thheller14:04:49

thats what :browser-test does?

Francesco15:04:54

well, actually yes. I am really sorry for the stupid question but your answer really helped me, thanks šŸ™‚

lilactown17:04:07

random question: does shadow-cljs send the form that was evaluated to the browser when you evaluate at the REPL?

thheller17:04:46

I think the source is included, not the form

Daniel Hines18:04:02

> source is included, not the form What does that mean? Arenā€™t they equivalent?

thheller18:04:57

"(foo)" vs (foo) (an actual list with foo symbol)

Daniel Hines18:04:20

Oh, gotcha. So source = string, form = data.

tomc18:04:05

I'm converting a figwheel-based project to shadow-cljs and finding that compilation w/ shadow-cljs fails on reagent's with-let macro, complaining that the vars referenced in the output of that macro are undeclared. Any possible causes come to mind?

thheller18:04:28

ancient version of reagent?

tomc18:04:00

0.8.1, I think that's the latest stable (checking now...)

tomc18:04:29

yeah that's the latest

thheller18:04:29

that should be fine I think

thheller18:04:12

maybe its not released yet?

tomc18:04:38

with-let has been in reagent for several releases now - it seems to me that the macro is evaluating just fine but the code it's outputting includes references to vars shadow-cljs doesn't know about for whatever reason. I'm also seeing warnings about "provide conflicts" due to re-frame and some others putting compiled assets in their jars - think it's possible that's related?

thheller18:04:24

yeah thats probably not helping

thheller18:04:27

what kind of warnings do you get?

tomc18:04:27

Pretty sure it's the same situation you talked about here: https://github.com/thheller/shadow-cljs/issues/473, ignoring the stuff about that person's macros + ns problems.

tomc18:04:01

Actually, some of the complaints are about goog libs, so maybe I have something else going on. For example: [2019-04-10 14:30:26.531 - WARNING] provide conflict for #{goog.labs.userAgent.engine} provided by goog/labs/useragent/engine.js and {"/out/goog/labs/useragent/engine.js" #{goog.labs.userAgent.engine}}

thheller18:04:05

yeah if compiled code is on the classpath that causes issues

thheller18:04:34

things in public/* are already filtered

thheller18:04:56

do you also have out/*?

tomc18:04:06

I do not have an out, just target, which I've been rm -rfing after the failed builds to make a clean slate. There are other possible complications w/ my build setup. I'm using lein for my deps + source-paths because some of my deps are stored in a private s3 bucket. My shadow-cljs config file is pretty simple though: {:lein {:profile "+dev-client"} :builds {:app {:output-dir "target/admin/client/public/js/compiled/" :asset-path "/" :target :browser :modules {:main {:entries [kc.admin.user]}} }}}

thheller18:04:26

I mean in the error messge

thheller18:04:40

I need to know your actual errors to help. not errors someone else had.

thheller18:04:04

> [2019-04-10 14:30:26.531 - WARNING] provide conflict for #{goog.labs.userAgent.engine} provided by goog/labs/useragent/engine.js and {"/out/goog/labs/useragent/engine.js" #{goog.labs.userAgent.engine}}

thheller18:04:46

this means there was an "unexpected" source file in /out/goog/labs/useragent/engine.js on the classpath, which can be in a jar. doesn't need to be one of YOUR paths

tomc18:04:34

Ok, I will look for something on the classpath containing the offending files. Thanks for the help.

thheller18:04:18

run shadow-cljs clj-repl then ( "the/path/it-reports-in-the-error")

thheller18:04:24

that'll tell you where its coming from (might need to strip the leading /)

tomc18:04:56

Yeah, that did it, thanks. Turns out the culprit was that same re-frame-utils lib from that issue. I didn't even realize it was in my project.clj. šŸ™ƒ

tomc18:04:26

I see the manual has a "what to do when things don't work" section that basically just says "ask on slack". Would you be interested in a PR describing this issue and its resolution in that section?

thheller18:04:21

I'd rather make the classpath filter smarter so people don't run into it anymore šŸ˜‰

tomc18:04:23

:thumbsup:

tomc18:04:28

Thanks again