Fork me on GitHub
#shadow-cljs
<
2020-04-26
>
wilkerlucio01:04:29

hello, I'm trying to add electron-updater to an app, but when the app starts I see this error shadow.js.shim.module$electron_updater.AppUpdater.checkForUpdatesAndNotify is not a function

wilkerlucio01:04:56

is shadow addimg some shim around electron_updater?

thheller06:04:15

shadow.js.shim.module$electron_updater = require("electron-updater"); is basically what it does

thheller06:04:45

so the function just doesn't exist on AppUpdater. maybe you need to instantiate it?

sergey.shvets01:04:49

Not sure, but have you tried to hint that this is ^js like in this part of the doc: https://shadow-cljs.github.io/docs/UsersGuide.html#externs? If you do that it shouldn't rename that function during compilation.

diego.videco03:04:08

Is there a way to require data from a .edn file?

diego.videco03:04:44

kind of when in webpack one can import a .json file?

radious03:04:39

Hi! I need some help, I'm new to shadow-cljs and unfamiliar with the larger JS/node ecosystem. I'm trying to import a npm package using shadow-cljs (the package is called ipfs) and use it in a browser app (:target is :browser). However, the compilation fails on the "crypto" package. ("The required JS dependency "crypto" is not available, it was required by "node_modules/nanoid/index.cjs".). From what I understand, crypto is something provided by node.js and not normally available in browsers. Does it mean that I need to use some kind of packer (like browserify or webpack) or can I somehow configure shadow-cljs to help me with that?

thheller07:04:24

install shadow-cljs in the project itself. that will bring in a few polyfills for packages like those

thheller07:04:40

but it also just might be that the package you are trying to use isn't compatible with the browser at all

radious05:05:45

Thanks! I do have shadow-cljs installed locally both. I tried both with --save and --save-dev (dunno if there's a difference). I didn't manage to get it working though. I'll stick to the CDN version and if I ever get deeper into this project, I might check what does webpack do differently. Regardless of that, thanks for shadow-cljs!

radious04:04:45

Oh, I can override it via :resolve in in :js-options. Is this how it's commonly done? Do I need to manually craft them for every node module?

radious04:04:22

Or should I just stop the fight and use a packed version of the library from CDN?

Spaceman05:04:09

is there a react-native framework or template for shadow like re-natal is for Figwheel?

Ahmed Hassan06:04:59

;; shadow-cljs.edn in project
{:deps {:aliases [:cljs]}}

;; ~/.shadow-cljs/config.edn
{:deps-aliases [:cider]}
What's difference between using :deps and :deps-aliases ?

thheller07:04:53

@ahmed1hsn the difference is that :deps-aliases allies to all projects and thus uses a different name

thheller07:04:38

@pshar10 I only made a couple examples for RN, otherwise you just use shadow-cljs. nothing more specific for RN really. https://github.com/thheller/reagent-expo https://github.com/thheller/reagent-react-native

Spaceman08:04:08

Sometimes when loading a function, I get the following error in the repl:

no source by provide: myapp.workspaces.dom
{:provide myapp.workspaces.dom}
ExceptionInfo: no source by provide: myapp.workspaces.dom
	shadow.build.data/get-source-id-by-provide (data.clj:184)
	shadow.build.data/get-source-id-by-provide (data.clj:181)
	shadow.build.data/get-source-by-provide (data.clj:187)
	shadow.build.data/get-source-by-provide (data.clj:186)
	shadow.cljs.repl/repl-compile/fn--37359/fn--37360 (repl.clj:453)
	shadow.cljs.repl/repl-compile/fn--37359 (repl.clj:429)
	shadow.cljs.repl/repl-compile (repl.clj:427)
	shadow.cljs.repl/repl-compile (repl.clj:424)
	shadow.cljs.repl/process-read-result (repl.clj:515)
	shadow.cljs.repl/process-read-result (repl.clj:491)
	shadow.cljs.devtools.server.worker.impl/do-repl-rpc (impl.clj:859)
	shadow.cljs.devtools.server.worker.impl/do-repl-rpc (impl.clj:813)
	shadow.cljs.devtools.server.worker.impl/eval38290/fn--38291 (impl.clj:894)
	clojure.lang.MultiFn.invoke (MultiFn.java:234)
	shadow.cljs.devtools.server.util/server-thread/fn--37822/fn--37823/fn--37831 (util.clj:285)
	shadow.cljs.devtools.server.util/server-thread/fn--37822/fn--37823 (util.clj:284)
	shadow.cljs.devtools.server.util/server-thread/fn--37822 (util.clj:257)
	java.lang.Thread.run (Thread.java:748)
And the only way out is to quit the repl and start it again. Why would this be?

thheller08:04:49

@pshar10 "Sometimes when loading a function" no clue what you mean by that

Spaceman08:04:53

I mean evaluating a function in cider or the repl directly gives this error.

Spaceman08:04:01

I don't know what causes it though.

Spaceman08:04:40

The error gives no context

thheller08:04:12

yeah I'll improve that error

thheller08:04:17

@pshar10 which shadow-cljs do you use? your stacktrace doesn't line up with my code at all? seems like its a rather old version?

Spaceman10:04:18

it's 2.8.102

thheller10:04:05

please open shadow-cljs clj-repl and try ( "shadow/cljs/repl.clj") and post the result

thheller10:04:38

it is very strange that your line numbers do not line up with the actual code

Spaceman10:04:48

This way it actually shows a different version:

( "shadow/cljs/repl.clj")
#object[.URL 0xfee791d "jar:file:/private/var/root/.m2/repository/thheller/shadow-cljs/2.8.93/shadow-cljs-2.8.93.jar!/shadow/cljs/repl.clj"]

Spaceman10:04:56

Why would this be?

thheller10:04:05

I guess you are using leiningen or deps.edn?

thheller10:04:19

then you have the old version in there

thheller10:04:32

the npm version is only for the command line stuff

Spaceman10:04:21

gotcha thanks

Chris McCormick13:04:38

is there a way to cause shadow-cljs's debug mode console to show a value? i am trying to debug on a platform without console access.

thheller13:04:28

@chris358 "debug mode console"? you mean inspect?

Chris McCormick23:04:42

i mean the text which shows up at the bottom of the window when you have e.g. an undefined symbol in your code at compile time. i wanted to mis-use this to quickly display some value at runtime instead of doing js/alert but i should probably just install proper tooling instead. or just a pre tag facepalm sorry it was late.

Chris McCormick23:04:28

yes, inspect is what i need. WOW.

pez13:04:25

I can't evaluate things in Calva's :node-library , atm. The nrepl load-file op works, but not eval. It never returns. This happened w/o me upgrading shadow-cljs, which was still on 2.8.77. Using .102 makes no difference. The only thing I think has changed is my node version, which is now v12.13.0. Could that be the issue?

thheller13:04:28

I don't know? works fine for me. any logs of the shadow-cljs server side maybe?

thheller13:04:01

I also released .103 earlier which should log REPL errors more visibly

pez14:04:31

It seems that if I restart the extension host (within where my library runs) and then connect the repl again, things start to work. I can live with that, but a bit strange that it started happening. Will use .103, and see if it says something more about the condition.

pez14:04:53

No matching version found for shadow-cljs@^2.8.103.

thheller14:04:25

oh sry. forgot to push the npm package. should be available now.

thheller14:04:19

@pshar10 you might also want to upgrade to 2.8.103. at least the errors should log more info now. hopefully that makes figuring out what is happening easier for me. Its just a raw data dump so I don't expect anyone to make sense of it, just report it.

bru14:04:21

@thheller FYI as of 2.8.102 something broke my (admittedly very unconventional) environment: I was loading a WebAssembly module, and I now see that the (automatically generated) js loader file does a require("fs"), making shadow-cljs complain with The required JS dependency "fs" is not available I reverted to 2.8.101 and everything started working again 🙂

thheller14:04:09

care to share which package that is?

thheller14:04:48

I didn't really change any of the polyfill behavior? so as long as you have shadow-cljs in the project it should find fs just fine?

bru14:04:19

that’s what I thought. I looked at the commits in .102 and couldn’t find the reason for it starting to complain at that point. Btw I can’t share that package as it’s proprietary, but I can try to create a minimal project that replicates the error. What’s the easiest way to setup a shadow-cljs project these days? (My codebase is 2 years old 🙂 )

thheller14:04:44

npx create-cljs-project foo

bru14:04:57

cool, that’ll be a useful exercise

thheller14:04:10

I only really need the package.json. if its just a blank require("fs") in the source file then only package.json can modify what that would do

bru14:04:40

ah that’s pretty basic, I don’t think there’s anything specific in there, let me check

thheller14:04:00

alongside your own build config of course

bru14:04:19

@thheller I’m preparing a gist with package.json & shadow-cljs.edn, bear with me

thheller15:04:12

@bru I didn't mean your package.json, I meant the package.json of the package that contains the require("fs")

thheller15:04:02

oh wait it isn't a package at all?

bru15:04:15

@thheller ups, gotcha. It doesn’t have one at the moment, it’s a legacy C++ app that’s being converted to a wasm module

thheller15:04:22

hmm weird, dunno how this is affected then?

bru15:04:13

eh, no idea. let me try to create that minimal shadow-cljs project, it will definitely be easier to debug a simpler setup

thheller15:04:07

just to check. you do have shadow-cljs IN THE PROJECT and not globally?

thheller15:04:18

hmm actually nevermind

bru15:04:25

it’s in the project, yes

thheller15:04:34

let me test something

bru15:04:57

sure, I’m carrying on with my refresher on how to setup a project in shadow 🙂

Lucy Wang15:04:42

My project depends on a js lib, say "foo", and I have cloned that repo locally. Is it possible to tell shadow-cljs to auto reload it when I modify the source of foo?

Lucy Wang15:04:06

I have tried "yarn link" but shadow-cljs seems not compatible with it

Lucy Wang15:04:48

{:tag :shadow.build.npm/missing-entries, :entries ["dist/index.js"], :package-dir #object[.File 0x69de6ee "/src/project-mine/node_modules/foo"]}
ExceptionInfo: package in /src/project-my/node_modules/foo specified entries but they were all missing

thheller15:04:55

@wxitb2017 shadow-cljs no longer auto-reloads changes in node_modules if individual files are modified but it should recompiled if the package.json of that package is modified

thheller15:04:25

so you can touch node_modules/foo/package.json

thheller15:04:37

well does the /src/project-my/node_modules/foo/dist/index.js exist?

Lucy Wang15:04:55

it exists if I install it normally, but not when I use yarn link

thheller15:04:57

if you just clone a package and not build it the files may just be missing

thheller15:04:24

most packages will have a build step they do before publishing

Lucy Wang15:04:52

totally makes sense

Lucy Wang15:04:58

just tried, it works. Thx a ton @thheller!

👍 4
Lucy Wang17:04:16

Anyone experienced shadow-cljs interferencing with input methods? I have a form input field in my react application, and as long as I add some println functions in my on-change function, after typing a char the input method would be automatically switched back from Chinese to system default (English)

Lucy Wang17:04:01

And 1. if I disconnect the browser from the repl - the problem magically disappears 2. reproducible on both chrome/ff/safari 3. only println would cause this problem, OTOH js/console.log is fine

Lucy Wang17:04:31

reworded ☝️

Lucy Wang17:04:25

nvm - turned out to be a bug os my system config

bru20:04:48

@thheller here’s the minimal project I promised -> https://github.com/bru/minimal-wasm-shadow-cljs

🙌 4
Chris McCormick23:04:18

thanks for sharing this!

papachan00:04:55

wow ! interesting !

thheller20:04:44

the glue code this generates is still horrible 😛

thheller20:04:01

but doesn't have anything to do with this particular problem. I just messed up a boolean statement 😛

bru20:04:04

I know, it wasn’t meant to be pretty, just straight to the point 😄

bru20:04:49

or, actually, demonstrate all the steps I need to take in the mothership project 😊

thheller20:04:09

I'm surprised this actually runs to be honest 🙂

thheller20:04:27

should be fine again in 2.8.104

bru20:04:43

I was too. It is very brittle though, I really don’t like having to keep babel in the picture for example

thheller20:04:34

can you just add all the generated files to the repo?

thheller20:04:41

I don't have any of the wasm related tools

bru20:04:00

@thheller those are already in place. You don’t really need to care about the last part of the setup (that’s just if you want to modify the C source).

bru20:04:25

uhm hang on, maybe I gitignored them

thheller20:04:33

yeah the .wasm file is missing at least

👍 4
bru20:04:28

@thheller added now, in /resources/wasm. I’m also writing a build script to simplify the setup

thheller20:04:42

don't bother 😛

thheller20:04:44

hmm why the babel stuff though?

bru20:04:12

too late, pushed 😉 babel was the easiest way I found to massage the js files to please the google closure compiler. Honestly for this minimal project it’s overkill, but as said I wanted to replicate the setup of the original one

bru20:04:49

:thinking_face: actually I’ll try to use this to come up with a plan to eradicate babel

thheller20:04:43

I just did 😛

bru21:04:42

awesome, your package-lock.json will be far slimmer now!

thheller21:04:04

if you add me to the repo I can push the branch I made

thheller21:04:55

the only problem I found is the ESM CommonJS interop. the generated libadd.js is commonjs but you glue.js was ESM

thheller21:04:07

so the import WasmAdder ... was the problem

thheller21:04:33

I switched it to

const WasmAdder = require('./libadd.js');

let add, malloc, free;

const wait = new Promise(done => {
  WasmAdder().then(Module => {
    malloc = Module._malloc;
    free = Module._free;
    add = Module.cwrap('add2', 'number', ['number', 'number']);
    done();
  });
});

exports.add2wasm = function add2wasm(x, y) {
  return wait.then(() => { return add(x, y); });
}
and then you can just compile it with only shadow-cljs

bru21:04:29

yup, that makes perfectly sense. the original project is a bit more complex as it includes JS from different styles / sources.

thheller21:04:05

yeah thats an issue. should be either all ESM or all CommonJS. the mix isn't supported well right now

bru21:04:34

eheh I noticed

bru21:04:00

btw, I invited you to the repo. If you want to push that branch, it’d be greatly appreciated

bru21:04:24

anyway, I hope this can help somehow push the wasm story for cljs. I know t’s brittle and sketchy at the moment, but it works and I’m mixing cljs, js and wasm in a single project (not saying it’s a good idea, but can be done 🙂 ).

👏 4
thheller21:04:30

well now I did 😛

👍 4
👏 4
bru21:04:18

thank you so much for your help! I can confirm 2.8.104 works on both the small and the big projects