Fork me on GitHub
#shadow-cljs
<
2020-01-25
>
jmckitrick02:01:30

I generated a luminus project with shadow support, and I’m trying to start CIDER to connect to both CLJ and CLJS. I got this error:

jmckitrick02:01:32

1. Unhandled clojure.lang.ExceptionInfo missing instance {} runtime.clj: 11 shadow.cljs.devtools.server.runtime/get-instance! runtime.clj: 8 shadow.cljs.devtools.server.runtime/get-instance! api.clj: 125 shadow.cljs.devtools.api/worker-running?

jmckitrick02:01:20

It’s been a while, but I’ve had CIDER running with shadow successfully, so I’m sure it’s just a step I’ve missed.

dpsutton04:01:27

can you tell me the template startup command you used @jmckitrick? I'll give it a shot and see what happens for me

dpsutton04:01:23

@jmckitrick the reason is that that's not a valid shadow-cljs project. They put the shadow-cljs.edn map inside project.clj and then use a plugin to re-extract it. That seems like just a weird thing to do

thheller10:01:34

thats what I said ... they insisted on the one-config-file-approach 😞

dpsutton04:01:31

(not you, just the template being like this)

dpsutton04:01:55

just pull the :shadow-cljs map out of project.clj and into a proper shadow-cljs.edn file and rip out that plugin. The downsides are that you'll have two config files. The upside is that all workflows and documentation will again apply to you. Seems like a steep price to pay to have a single file.

dpsutton04:01:06

although it seems like this will side effect and write package.json and shadow-cljs.edn if you run the plugin once and then everything should work from there. just sounds like a bunch of headache for no real net gain

jmckitrick04:01:06

Ah, ok. Let’s try it….

jmckitrick04:01:27

@dpsutton Am I better off starting clj and cljs, and connecting from CIDER, or starting both from within CIDER itself?

jmckitrick04:01:22

Hmm. Still having the same issue. Well, I’m going to call it a night and pick up tomorrow afternoon.

dpsutton05:01:58

until there's a shadow-cljs.edn file there's no hope of this working in CIDER. run lein shadow compile app and it should make a package.json file and a shadow-cljs.edn file. it copies all the deps over it seems instead of just the ones you need so probably prune that down. at that point excise all that junk and just embrace the two systems

dpsutton05:01:16

i don't think it matters about clj and cljs separately. they ultimately end up doing the same thing. the important thing is that a valid shadow-cljs.edn file exists and you've run npm install. let the plugin do that once and then you should be good to go

thheller10:01:07

@jmckitrick you need to start the shadow-cljs instance if you run it embedded in a regular CLJ project/REPL. see https://shadow-cljs.github.io/docs/UsersGuide.html#embedded. not sure about the cider parts but the "missing instance" is caused when trying to call shadow-cljs API method without a running server instance in that JVM, which you need to start in embedded mode.

Philipp Siegmantel13:01:27

Hello, I have a problem with the karma target. Everything works fine in the repl, but when I run karma, I get the following exception

TypeError: s.replace is not a function
      at Object.clojure$string$replace_all [as replace_all] (karma-test.js:49567:10)
      at Object.clojure$string$replace [as replace] (karma-test.js:49626:23)
      at Object.shadow$test$karma$indent [as indent] (karma-test.js:82522:23)
      at shadow$test$karma$format_log (karma-test.js:82613:214)
      at karma-test.js:29716:89
      at karma-test.js:29717:3
      at Object.sval (karma-test.js:23585:110)
      at Object.cljs$core$ISeqable$_seq$arity$1 (karma-test.js:23736:10)
      at Object.cljs$core$seq [as seq] (karma-test.js:16711:13)
      at karma-test.js:29690:36
The code I added is the following.
(defn summarize-results' [spec-check]
  (map (fn [x] (pprint/write (stest/abbrev-result x) :stream nil)) spec-check))

(defn check' [spec-check]
  (is (nil? (-> spec-check first :failure)) (summarize-results' spec-check)))
Does anybody have a solution? I already tried to add a "-test" postfix to the namespace the code is in.

thheller13:01:37

@philipp.siegmantel you are passing nil to something that expects a string

thheller13:01:45

can't tell what your functions are supposed to be doing or where you added them

thheller13:01:19

oh no wait you are not passing nil, you are passing something that is not a string when a string is expected

thheller13:01:46

so juding from the code something espects message to be a string but isn't

Philipp Siegmantel13:01:41

@thheller With message you mean the second argument to is? That makes sense. I copied the code from somewhere but summarize-results' returns a seq not a string. Thank you for your help.

thheller15:01:04

I didn't even know is takes a second arg at all 😛

jmckitrick15:01:16

Would it make sense to create the app from luminus without shadow then add it manually?

thheller15:01:12

not really?

thheller15:01:09

I mean sure it probably helps you understand the setup better and you don't have lein-shadow (which I don't recommend anyways)

thheller15:01:58

but you can just use the generated code run it once so it creates the shadow-cljs.edn file and then remove lein-shadow entirely

jmckitrick16:01:32

This is what I get for not taking copious notes last time I worked on my project. I’m going to start from scratch shortly, but still using a luminus template. I’ll work my way through all the docs and hopefully get something working for my new project.

jmckitrick16:01:35

So you are saying move the shadow part of the project file into the standalone shadow edn file, right?

dpsutton17:01:12

look at my output from my shell above

dpsutton17:01:22

there is no shadow-cljs.edn file nor package.json file. Then i run lein shadow compile app and the plugin generates those files from the project.clj file. At this point you have a normal shadow-cljs.edn file. At this point, remove that plugin and delete the shadow-cljs entry in the project.clj file and pretend like that stuff never happened

dpsutton17:01:46

CIDER just starts up shadow normally and now will print out the startup commands so you can seem them. super straight forward and it should work on any standard shadow project. if you run into any issues open an issue on CIDER's github and i'll get it patched up for you

jmckitrick17:01:32

Ok, I’m getting there. When running CIDER and jack-in clj and cljs, I’m still seeing the ‘missing instance’ where @thheller says I need to be running shadow server. Does that sound right?

thheller17:01:05

@jmckitrick it depends if you want to run shadow-cljs in embedded mode or not. if the instance is missing then you are likely connected to the luminus CLJ server. so you can either embed shadow-cljs into that or run it separate and connect to that instead.

jmckitrick17:01:01

Which one is best for getting full CIDER functionality in CLJ and CLJS?

jmckitrick17:01:14

Maybe @dpsutton would have insight on that

Kamuela17:01:52

Is the beginner guide from the website still up to date? It's from the middle of 2017

thheller17:01:04

which guide?

Kamuela17:01:21

It's linked on http://shadow-cljs.org as Beginner Guide

thheller17:01:07

yes thats still current

dpsutton17:01:21

i'm having a different experience. i ran the plugin so i had a shadow-cljs.edn file. I deleted the shadow-cljs key from project.clj. I then ran cider-jack-in-cljs from the shadow-cljs.edn file and the repl starts up.

dpsutton17:01:24

;;  Startup: /home/dan/projects/node/bin/npx shadow-cljs -d nrepl:0.6.0 -d cider/piggieback:0.4.2 -d cider/cider-nrepl:0.23.0 server
;;
;; ClojureScript REPL type: shadow
;; ClojureScript REPL init form: (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :app) (shadow/nrepl-select :app))

dpsutton17:01:47

this is displayed in the repl buffer. its just running npx shadow-cljs and then shadow/watch :app, nrepl-select app

jmckitrick17:01:51

ok let me try that command, rather than clj and cljs

jmckitrick17:01:11

I assume you didn’t start anything else, in other terminals?

dpsutton17:01:21

correct. everything through just the cljs command

dpsutton17:01:08

do them separately. you want to use lein for the backend and shadow-cljs for the frontend. it seems like jack in clj&cljs will use the same build tool for both

jmckitrick17:01:45

But I can still get CIDER to connect to both? I used to do that with the old figwheel.

dpsutton17:01:14

yes. run cider-jack-in-clj and then separately cider-jack-in-cljs

4
jmckitrick17:01:04

So… cider-jack-in-cljs seems to work… I selected shadow, then the build, and it’s offering to open a page in the browser that shows active http servers.

jmckitrick17:01:17

Now I’m going to try cider-jack-in-clj

jmckitrick17:01:03

It’s asking if I want to open a sibling session… I’m saying ‘yes’

jmckitrick17:01:55

It’s not letting me do both. Trying to connect to CLJ seems to silently fail.

dpsutton17:01:04

lets go to #cider

Kamuela17:01:35

The Beginner Guide starts with > Say you have a project:

├── README.md
├── assets
│   └── index.html
├── package.json
├── shadow-cljs.edn
├── src
│   └── app
│       ├── lib.cljs
│       └── main.cljs
└── yarn.lock
And doesn't really explain how you would have gotten there in the first place, do you generally start a new shadow-based CLJS project with an npm-init and install, then include shadow-cljs.edn and plugin shadow at that point?

thheller17:01:52

@kamuela if you want that structure then you can start by cloning this repo https://github.com/minimal-xyz/minimal-shadow-cljs-browser

thheller17:01:23

or you can follow the "official" quickstart and use npx create-cljs-project foobar https://github.com/thheller/shadow-cljs#quick-start

Kamuela17:01:59

Ah right, that quick start isn't mentioned at all on http://shadow-cljs.org

Kamuela17:01:01

Probably from the perspective of knowing any possible way to work with a shadow project that beginner's guide is still relevant, but from a new perspective I'd definitely say the create-react-app route is the preferred onboarding

thheller17:01:40

well the issue is that shadow-cljs is a build tool. I don't really want to write framework specific things like create-react-app

thheller17:01:57

if you want that then its typically best to go with a template for the given framework you want

thheller17:01:06

eg re-frame or fulcro

thheller17:01:18

there is also create-cljs-app

❤️ 4
Kamuela17:01:12

Guess it depends on the use case you have in your head. If the majority of people have pre-existing apps, and you're speaking to an experienced audience, then I can see the message being more like a look at how we can simplify your dev experience. But for someone like me who's brand new, it's nice to have a create-cljs-project path to follow

Kamuela18:01:19

All I'm really saying is that the quick-start is great and the main site pushing the beginner's guide threw me a bit

dpsutton18:01:01

i did a presentation on getting up and running with shadow recently

dpsutton18:01:33

there are links to a presentation site with the slides, link to a repo that i walk you through building, and a link to the site running the example app

Kamuela18:01:59

That Netlify bit is awesome

dpsutton18:01:27

Yeah netlify and shadow are a dream together

Bobbi Towers07:01:16

I used your presentation several times and it worked great, thanks! But I find myself making shadow-reagent apps so frequently that I decided to take advantage of the Github template feature: https://github.com/porkostomus/shadow-reagent

knubie18:01:07

Is there some specific configuration I need to add to get shadow-cljs’ hot code reload to work with react-native?

thheller18:01:14

specific configuration isn't required, just the code needs to be actually hot-reloadable. which is what that snippet provides.

👍 4
knubie19:01:10

Also need to disable React Native’s “fast refresh” right?

knubie19:01:13

Got it working, thanks!