Fork me on GitHub
#shadow-cljs
<
2019-08-15
>
Aklscc02:08:56

hello, guys, I have some problems with using shadow-cljs, leiningen and cursive IDE in Intellij. I want to start a repl of clojurescript in the Intellij, and do as following: Add a port config in shadow-cljs.edn

clojure
:nrepl {:port 9600}
Add Edit Configurations in Intellij I add a Clojure REPL of Remote with the Host 127.0.0.1, and Port 9600. Start shadow-cljs Server in Terminal I open a terminal and do:
# app is the app-id
$ shadow-cljs watch app
Run the REPL to connect the Server in Intellij I click the green button of the run in the left-top of of Intellij. As default, it will connect a clojure REPL, and I can't switch it to clojurescript REPL. How should I do? And I also want to load the project to REPL, too. Is there anyone having an experience about it?

Aklscc02:08:53

And my build target is npm-module, then use it in Expo App.js.

thheller07:08:23

:npm-module is tricky with regards to REPL setup. can you not use the proper :react-native target?

Aklscc07:08:55

@thheller. I use the` npm-module` in App.js, it's convenient, so I don't think more about it. The :react-native target is enough simple?

thheller07:08:13

dunno what you are doing

thheller07:08:25

if you use :npm-module you must set :runtime :react-native in your build config

thheller07:08:50

and then manually in App.js require("./app/shadow.cljs.devtools.client.react-native")

thheller07:08:01

that performs the REPL setup client side

thheller07:08:24

in cursive you then call (shadow.cljs.devtools.api/repl :app) to switch to the CLJS repl for :app

Aklscc08:08:44

@thheller. It works well to switch clojure REPL to clojurescript's. I'm using Expo and React Native to do an app. After do as above, any input will get No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.

thheller08:08:18

yes that means that your app has not loaded the necessary REPL js

thheller08:08:27

which you do with the require I added above

thheller08:08:39

OR it could be that the websocket just failed to connect

thheller08:08:10

note that only the :npm-module target has to do this manual setup

Aklscc08:08:48

@thheller. I think it's beacause of configuration in App.js. What should I do after require("./app/shadow.cljs.devtools.client.react-native") in App.js? Are there another operations in App.js? At beginning, I just refer npm-module compiled and export a App(), just as default of expo init yields.

Aklscc08:08:56

Yes, maybe something about websocket, I start expo and run it on IPhone, then it print WebSocket disconnected with a long Map.

thheller08:08:42

no that is all you need to do

thheller08:08:57

but given that you run on an iPhone which connects over the network

thheller08:08:09

it might be picking the wrong IP to connect to

thheller08:08:20

check shadow-cljs watch app --verbose

thheller08:08:27

it'll log the IP it is using on start

thheller08:08:59

and if that is the wrong one you can override it with shadow-cljs watch app --config-merge '{:local-ip "1.2.3.4"}'

thheller08:08:12

or set :local-ip in your build config

Aklscc09:08:42

I'm so sorry bothering you again. But it still doesn't work after I try to set local-ip. I don't know how the shadow-cljs work and which ip to set for it. It's My work environment:#1. start shadow-cljs and expo on two terminals; #2. set shaodw-cljs nREPL port 9600, which in localhost and LAN, you can connecnt it in any one; #3. set Cursive nREPL remote host and port 127.0.0.1:9600; #4. Run app on IPhone by QR code with LAN option

thheller09:08:54

localhost is not correct

thheller09:08:03

and you are configuring the wrong thing

Aklscc09:08:03

I also try to set Cursive nREPL Remote with LAN as host. It doesn't work too.

thheller09:08:26

you need to configure the part where your iPhone connects to your PC

thheller09:08:34

so the IP of your machine on the network

thheller09:08:49

I don't know what that is so I cannot tell you

thheller09:08:57

but cursive is not involved in this process

thheller09:08:14

which OS are you on?

thheller09:08:29

so do you know how to look up your network ip? might be something like ifconfig but I can't remember

thheller09:08:48

google that part. nothing to do with either react-native or shadow-cljs. purely your OS IP is needed

thheller09:08:06

usually something like 192.168.1.5 or so

Aklscc09:08:07

I have try it, use the IP of my OS. But it doesn't work, and the repl print No application has .... too

thheller09:08:37

ok what did you do?

Aklscc09:08:17

set local-ip as the IP of my OS

thheller09:08:25

how exactly?

Aklscc09:08:15

the cursive repl print No application has ....

thheller09:08:35

yes. please tell me exactly where you set the local ip

thheller09:08:38

the full command

thheller09:08:44

and preferably the full build config

thheller09:08:50

it matters where you set it

thheller09:08:07

I can currently only guess what you are doing

thheller09:08:16

which makes this process extremele slow

thheller09:08:49

The message is telling you what your react-native app on your iphone has not connected back to the shadow-cljs process

thheller09:08:03

it doesn't matter what you have configured in cursive for that part

Aklscc09:08:58

Ok. I will give a specific list of it. I'm sorry for that, thanks for your sincere help. I'm a rookie in Clojure, so there are many thing unknown.

thheller09:08:35

yeah. I'm writing a REPL troubleshooting guide currently. hopefully that explains things a bit better than I can do here in slack

Aklscc12:08:12

@thheller. This a specific configuration list. Maybe It can express more.

Aklscc12:08:25

I have run it by use ":target :react-native" successfully. But when use ":npm-module" as ":target", it seems websocket problem.

Aklscc12:08:54

In the latest version-2.8.47, you even can't run a expo start if config as above.

thheller12:08:36

"The operation couldn’t be completed. Connection refused"

thheller12:08:44

this is the relevant error here

thheller12:08:52

the expo app fails to connect to the shadow-cljs process

thheller12:08:30

which according to your ip config would be running at http://192.168.50.244:9630

thheller12:08:38

you can just test an open that in a regular browser

thheller12:08:11

(from your iphone)

thheller12:08:30

could be that you have a firewall blocking that access

thheller12:08:35

or that it isn't the correct IP

thheller12:08:03

I'm unsure why the react-native target works though.

thheller12:08:10

is there any particular reason you are using :npm-module?

Aklscc12:08:51

The ip of http://192.168.50.244:9630 has the content of "loading...", and the title is my app name.

Aklscc12:08:09

Maybe the target :npm-module have some problem when work with expo?

Aklscc12:08:43

I use react-native as target, works well.

thheller12:08:05

well why are you using :npm-module?

thheller12:08:25

:target :react-native is meant for expo as well

thheller12:08:36

the page should also show more than "Loading ..."

Aklscc12:08:38

I learn the expo docs first, it looks like use App.js as a entry file is very simple, and needn't manually add AppRegistry. So I do it as in clojurescript.

Aklscc12:08:55

Okay, I will try it, really thank you.

tianshu03:08:57

Hi, @thheller. In development, shadow-cljs will generated bunch of files, can I separate entry files from other files? since the release mode there should be only entry files, I want to keep the directory clean. I can add a second path to source paths, I just wonder can I tell shadow-cljs to put the file there?

thheller07:08:02

@doglooksgood the files are generated there to stop a metro exception from happening

thheller07:08:31

if they aren't there metro will throw an exception when displaying redbox/yellowbox dialogs

thheller07:08:41

they aren't technically used for anything

thheller07:08:01

release builds don't use them so you could just rm -rf app/* && shadow-cljs release app

thheller07:08:11

just clean them before you make the release build

danielneal12:08:40

dumb question I couldn’t figure out from the docs - where do I put an init function that I want to be called only in dev.

danielneal12:08:12

Thinking about preloads, but should the function then be at the top level in the namespace or does it need some metadata

danielneal12:08:22

(it’s a websocket reconnection for remote inspection)

thheller12:08:48

dev only code goes into :preloads yes (and you just run the code directly)

kasuko15:08:34

Alright, 99% done my conversion from lein to shadow-cljs. Latest issue, I am trying to replace our dependency on the lein-cljfmt plugin. I am trying to run cljfmt using shadow-cljs run but it looks like shadow-cljs is trying to consume my --file-pattern argument for itself.

thheller15:08:28

try npx shadow-cljs run cljfmt.main/-main -- fix --file-pattern '\/[^.]+\.clj[sxc]?$' src test

kasuko15:08:19

Awesome works perfectly! Thanks!

thheller15:08:51

So I don't forget to fix this properly again 😉

thheller15:08:08

-- is sort of convention on linux or so

kasuko15:08:11

Ya, I've definitely seen an used that often when dealing with git ... just didn't think to try it with shadow-cljs

malch17:08:09

Hello! I'm trying to use shadow-cljs with Cider, but got this error:

user> (server/start!)
Aug 15, 2019 8:05:01 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.7.2.Final
Aug 15, 2019 8:05:01 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.7.2.Final
Aug 15, 2019 8:05:01 PM org.jboss.threads.Version <clinit>
INFO: JBoss Threads version 2.3.2.Final
shadow-cljs - server version: 2.8.42 running at 
shadow-cljs - nREPL server started on port 9876
:shadow.cljs.devtools.server/started
user> (shadow/watch :app)
[:app] Configuring build.
[:app] Compiling ...
[:app] Build completed. (175 files, 1 compiled, 0 warnings, 2.73s)
:watching
user> (shadow/nrepl-select :app)
Execution error (IllegalStateException) at shadow.cljs.devtools.api/nrepl-select (api.clj:377).
Can't change/establish root binding of: *nrepl-cljs* with set
last two lines

malch17:08:35

could someone help me?

thheller17:08:43

@malch the middelware isn't loaded. dunno how to configure that though

thheller17:08:30

might need to use the ns shadow.cljs.devtools.server.nrepl04 instead of shadow.cljs.devtools.server.nrepl

thheller17:08:33

depends on your nrepl version

malch17:08:18

thank you, will try to investigate further

malch17:08:34

@thheller Thank you! nrepl04 middleware worked perfectly simple_smile

tianshu19:08:20

@thheller thanks for the reply, I'm very sorry I didn't point out I want specify a output-to at :browser target. I want make my src/main/resources/public/compiled directory clean. Of course I can delete it before build.

dobladez19:08:24

hi... not specific to shadow-cljs at all, but: Any recommendations or common practice to separate CLJ vs CLJS deps (in the same source tree)? All open projects I've looked at seem to keep all deps together... which I don't like

thheller20:08:17

when using lein I usually create a :cljs profile there I put my CLJS deps (eg. the shadow-cljs project itself)

thheller20:08:41

I have also just put CLJS deps in shadow-cljs.edn and server side in a separate deps.edn

thheller20:08:01

it really is up to you, so if you don't like keeping it together .. don't 😛

dobladez20:08:34

is there a way to tell shadow-cljs the name of the deps.edn file? (say, deps.cljs.edn?).

thheller20:08:09

no? wasn't aware that was even an option clj supported?

dobladez20:08:16

I'm using lein-tools-deps... which has the option to do so

dobladez20:08:36

but yes... most tooling around deps expects deps.edn

dobladez20:08:22

in project.clj, this seems to work: :lein-tools-deps/config {:config-files [:install :user "./deps.clj.edn"]}

thheller20:08:22

well if you tell me which command line option it is I can add it

thheller20:08:35

can't use lein-tools-deps

dobladez20:08:24

sure, I'm just saying... for the server-side piece (using lein) that's one way I found which might work

thheller20:08:49

if you want to find out how they did it I'd be happy to accept a PR for that

dobladez20:08:01

I'll take a look

dobladez20:08:07

thanks again!

dobladez20:08:21

using profiles sounds like a valid option too

tvaughan20:08:09

Has anyone successfully compiled a rum project using shadow-cljs? I used npm to install react, react-dom, and create-react-class per https://shadow-cljs.github.io/docs/UsersGuide.html#_missing_js_dependency and https://github.com/thheller/shadow-cljs/issues/199. When I try to compile a simple hello-world application that does nothing other than require rum.core I get The required JS dependency "object-assign" is not available, it was required by "node_modules/react/cjs/react.production.min.js". Yes, I'm aware I could also use npm to install object-assign, but this just doesn't seem right to me. Sorry, I'm sure this is a question that's repeatedly asked. I've looked at a lot of examples and I don't see anything different between them and what I have. PS - I did repeatedly npm install all missing dependencies and it does eventually compile.

thheller20:08:50

object-assign should have been installed when you did npm install react since it is listed as one of its dependencies? https://unpkg.com/[email protected]/package.json

thheller20:08:39

maybe try restarting the shadow-cljs process

thheller20:08:55

it sometimes gets into a confused state if too many node_modules folders are modified

tvaughan20:08:58

Yes, it was installed underneath react/, not at the top-level of node_modules/ which appears to be required by shadow-cljs

thheller20:08:15

why was it installed nested?

tvaughan20:08:23

I have no idea

tvaughan20:08:52

I just ran npm install react ...

tvaughan20:08:02

This is on Ubuntu 18.04 which has npm v3.x

thheller20:08:20

well you definitely need a newer npm version in that case

thheller20:08:24

that is like ancient history

thheller20:08:46

what is node -v?

tvaughan20:08:32

# node -v
v8.10.0

thheller20:08:07

and npm -v?

thheller20:08:27

node is also kinda old but that would be ok

thheller20:08:46

a lot has changed in npm however so I'd definitely upgrade that since it has gottan way more reliable

tvaughan20:08:44

# npm -v
3.5.2

thheller20:08:13

yeah definitely upgrade that

tvaughan20:08:44

Trying now...

tvaughan21:08:15

OK. So I upgrade though I don't think that matters. Witness:

# npm install -g ...
# ll /usr/lib/node_modules/                                                                                                                                                  
drwxr-xr-x 1 root root 4096 Aug 15 20:52 ./
drwxr-xr-x 1 root root 4096 Aug 15 20:51 ../
drwxr-xr-x 3 root root 4096 Aug 15 20:52 create-react-class/
drwxr-xr-x 8 root root 4096 Aug 15 20:51 npm/
drwxr-xr-x 5 root root 4096 Aug 15 20:52 react/
drwxr-xr-x 5 root root 4096 Aug 15 20:52 react-dom/
Vs
# npm install ...
# ll node_modules/
drwxr-xr-x 25 root root 800 Aug 15 20:55 ./
drwxr-xr-x 19 root root 608 Aug 15 20:55 ../
drwxr-xr-x  3 root root  96 Aug 15 20:55 .bin/
drwxr-xr-x 10 root root 320 Aug 15 20:55 asap/
drwxr-xr-x 20 root root 640 Aug 15 20:55 core-js/
drwxr-xr-x  9 root root 288 Aug 15 20:55 create-react-class/
drwxr-xr-x  9 root root 288 Aug 15 20:55 encoding/
drwxr-xr-x 10 root root 320 Aug 15 20:55 fbjs/
drwxr-xr-x  8 root root 256 Aug 15 20:55 iconv-lite/
drwxr-xr-x  6 root root 192 Aug 15 20:55 is-stream/
drwxr-xr-x 14 root root 448 Aug 15 20:55 isomorphic-fetch/
drwxr-xr-x  7 root root 224 Aug 15 20:55 js-tokens/
drwxr-xr-x 10 root root 320 Aug 15 20:55 loose-envify/
drwxr-xr-x 13 root root 416 Aug 15 20:55 node-fetch/
drwxr-xr-x  6 root root 192 Aug 15 20:55 object-assign/
drwxr-xr-x 17 root root 544 Aug 15 20:55 promise/
drwxr-xr-x 14 root root 448 Aug 15 20:55 prop-types/
drwxr-xr-x  9 root root 288 Aug 15 20:55 react/
drwxr-xr-x 18 root root 576 Aug 15 20:55 react-dom/
drwxr-xr-x  9 root root 288 Aug 15 20:55 react-is/
drwxr-xr-x  9 root root 288 Aug 15 20:55 safer-buffer/
drwxr-xr-x 12 root root 384 Aug 15 20:55 scheduler/
drwxr-xr-x  5 root root 160 Aug 15 20:55 setimmediate/
drwxr-xr-x 12 root root 384 Aug 15 20:55 ua-parser-js/
drwxr-xr-x  8 root root 256 Aug 15 20:55 whatwg-fetch/
# nodejs -v
v12.8.1
# npm -v
6.10.2
Looks like global installs cannot be supported by shadow-cljs

thheller21:08:55

uhm global install?

thheller21:08:30

not sure why you'd be doing that but if npm is installing things differently there then yes that isn't supported

tvaughan21:08:01

Because I'm building a docker image...

thheller21:08:41

not sure why that matters?

tvaughan21:08:12

I want the dependencies saved in the docker image

thheller21:08:36

but why does it have to be a global install for that?

thheller21:08:55

that also seems like kind of a bad idea given that you can't manage dependencies well that way?

tvaughan21:08:49

They're specified explicitly

tvaughan21:08:32

Thanks for the help @thheller!

lilactown21:08:35

You shouldn't use global npm modules

tvaughan21:08:58

The only other alternative is to check-in node_modules/ into the repo. Is this the recommended approach?