Fork me on GitHub
#clojurescript
<
2020-10-15
>
macrobartfast00:10:32

after creating a project with

lein new re-frame demorf +cider
and then
lein deps
and
npm install
and then running in emacs
cider-jack-in-cljs
I got a user> prompt, but attempting to eval the :require statement in core.cljs with
cider-eval-defun-at-point
generated
Unhandled java.io.FileNotFoundException
   Could not locate reagent/dom__init.class, reagent/dom.clj or
   reagent/dom.cljc on classpath.
which I assume will apply to every dependency. How should I start troubleshooting this?

dpsutton00:10:58

that template does weird stuff. it uses lein-shadow, a plugin that (imo) just adds more layers to tooling for no real benefit

dpsutton00:10:45

that template doesn't include react, react-dom and create-react-class, all of which are necessary for shadow.

dpsutton00:10:09

can i recommend lein new reagent demorf2 +shadow-cljs over what you are using? and then add re-frame from there?

p-himik00:10:07

> that template doesn't include react, react-dom and create-react-class, all of which are necessary for shadow. Not sure I get that. How is React necessary for shadow-cljs? Also, the need for create-react-class is no longer there with modern versions of React.

p-himik00:10:49

Ah, you probably meant the way shadow-cljs works with cljsjs.

dpsutton00:10:56

Yeah it doesn’t bring in the cljsjs versions and uses the npm distributed packages. Those are conspicuously absent from the package.json file though

👍 3
macrobartfast01:10:41

@U11BV7MTK you can definitely recommend another template!

macrobartfast01:10:48

I will try that.

macrobartfast01:10:58

in the reagent template, ran into a

Unhandled java.lang.Exception
   Failed to launch Figwheel CLJS REPL: nREPL connection found but
   unable to load piggieback.  This is commonly caused by A) not
   providing piggieback as a dependency and/or B) not adding
   piggieback middleware into your nrepl middleware chain.
error, so found https://github.com/reagent-project/reagent-template/issues/111

macrobartfast01:10:29

assuming you use emacs, how would you go about setting up an environment that allows you to evaluate code in a buffer?

macrobartfast01:10:53

I’ll admit, I’m fully confused these days by the options available.

macrobartfast01:10:43

I used to just connect to an nrepl instance in a terminal to evaluate Clojure, but now it seems it’s recommended to jack in.

macrobartfast01:10:23

I never know whether I should jack in to just clj, or clj&cljs.

macrobartfast01:10:10

@U11BV7MTK @U2FRKM4TW if either of you know of a quick start or demo app that uses re-frame/reagent with a working current approach, be sure to let me know!

macrobartfast01:10:27

it seems like a lot of the demo projects are maybe not current.

macrobartfast01:10:58

unfortunately for me, lots of tutorials seem to use Calva, alas… maybe I should consider switching.

dpsutton01:10:02

can you tell me the exact command you used to create your template?

macrobartfast01:10:04

lein new reagent demorf2 +shadow-cljs +cider

macrobartfast01:10:27

I added cider because I figured I needed it, but I’m pretty lost in the ecosystem now…

macrobartfast01:10:10

basically, I’m trying to have an environment wherein I can evaluate code from statements in the buffer (as opposed to the repl(s) themselves.

dpsutton01:10:36

i'm confused why you're talking about figwheel then

dpsutton01:10:42

if you are using +shadow-cljs

dpsutton01:10:20

works for me

dpsutton02:10:12

1. lein new reagent demorf2 +shadow-cljs (drop +cider. cider knows what to do) 2. cd demorf2 && npm i get our deps 3. open up server.clj and cider-jack-in. make sure to choose lein for this when asked which to use this uses a server to serve our assets. so start the server up otherwise no way to get our js. (not technically true as shadow can serve this but we're gonna use the backend provided) 4. go to core.cljs and cider-jack-in-cljs and choose shadow-cljs when jacking in. it should then ask you which build tool you are using and select shadow. Then it will ask you which build to use and select :app. Load the port specified in server.clj (i changed it to 3002 as the default 3000 was already in use) 5. visit localhost:3000 (or whatever port you are using)

dpsutton02:10:29

its a lot but you get used to it when you understand what's going on. i looked at the template and saw there were backend files and a jetty server so fire that up. then go fire up cljs. this template uses shadow-cljs for the frontend and lein for the backend shadow-cljs.edn and project.clj files respectively so those are the build tools to select for frontend and backend

dpsutton02:10:47

i hope that clears it up @U0X9N9ZK5

macrobartfast02:10:38

I’ll try it now! thank you so much! I was thinking about figwheel and shadow-cljs because I didn’t yet understand they were alternatives.

macrobartfast02:10:51

I’ll give your approach a try; if it works, I’ll be having your instructions etched into titanium and wall mounted in an oak frame.

macrobartfast02:10:33

omg omg omg :star-struck:

macrobartfast02:10:47

It worked. I’m so completely grateful.

dpsutton02:10:35

i'm glad. there's lots of pieces that when just starting can be really confusing to figure out. i wrote out in addition to the steps i took also the way i figured out what steps to do so i hope that helps

macrobartfast03:10:10

and I’m really grateful for the latter.

macrobartfast03:10:21

(as well as the former, of course)

macrobartfast03:10:57

getting a project running is often my stumbling block (granted, I use Emacs, which I guess makes it a bit more tricky)

macrobartfast03:10:11

but… long live Emacs!

p-himik06:10:55

Sorry I wasn't here to help, was asleep. But I use vim either way. :D

macrobartfast17:10:14

@U2FRKM4TW I asked you to turn Slack notifications on high volume next to you when sleeping.

macrobartfast17:10:23

don’t let it happen again.

p-himik17:10:20

Aye aye captain.

macrobartfast17:10:21

Good for you on Vim. My Emacs addiction is a questionable one. The Boot crowd were Vim users, I noticed.

macrobartfast17:10:18

I have a question for you or @U11BV7MTK though… I assume the cljs repl is evaluating in the browser, right?

macrobartfast17:10:27

or is it spinning up a node instance or something?

macrobartfast17:10:57

evaluating the :require in server.clj is working great (I get my familiar ‘nil’ response) but doing the same in core.cljs is not producing a response…

macrobartfast17:10:54

nor evaluating (+ 1 1)… unless I change the Emacs mode for the core.cljs buffer to ‘clojure-mode’, in which case (+ 1 1) evaluates ok, but I get an error on the :require statement (can’t find the first dependency).

macrobartfast17:10:09

could be more of an Emacs integration thing.

macrobartfast18:10:28

basically, having issues with the cljs buffer evaluation. evaluating (js/alert "foo") from within core.cljs throws ‘no such namespace’. I noticed that that prompt was demorf2.repl> as opposed to the demorf2.server I saw in @U11BV7MTK’s screenshot.

macrobartfast18:10:52

I’m not up to speed on Slackiquette… I probably should post each new issue in a channel as opposed to hammering you two just because you were so helpful yesterday. I’ll try to do that.

dpsutton18:10:19

so its important to remember that there are two repls: clj and cljs. CIDER unfortunately only knows how to eval forms in the last repl that your cursor was in. so click in the cljs repl and then click in the cljs buffer and eval (js/alert "hi from cljs") or something and it should work

macrobartfast18:10:51

aha… works!!

dpsutton18:10:50

and the repl namespace is important if you are sending forms to the repl buffer but not if you are just evaluating inline. i put mine into the demorf2/server buffer to call the -main function is all

macrobartfast18:10:28

I have been putting calls to -main in comment blocks for inline evaluation, but that sounds better.

nickt12:10:23

hey y'all, quick question. I have a defrecord that I'm using in my code, and at some point I want interop with js so I cljs->js and a .stringify js/jSON. I'm wondering, is there a way to then do the reverse? From that json stringified string, do a .parse js/JSOn, and a js->cljs and recover the fact that some of those objects are actually records?

nickt12:10:05

or maybe I can go from my record (which has an array of other records as children) to some string representation and back safely? I don't need JSON specifically

thheller12:10:12

> I don't need JSON specifically

thheller12:10:17

why are you converting to JSON then?

nickt12:10:14

I just need to get to a string representation

nickt12:10:18

(and back)

nickt12:10:38

and JSON seemed like the answer until I realized the fact that these objects are actually records is lost

thheller12:10:53

for records you'll need to add a custom read/write handler but thats quite easy to do

thheller12:10:41

or just pr-str + cljs.reader/read-string works too

nickt12:10:15

(read-string (pr-str (Node. 1 2 3)))

nickt12:10:23

that doesn't seem to work in my repl?

thheller12:10:47

records need special attention

nickt12:10:20

hm mind pointing me to some docs on that?

thheller13:10:16

sorry busy. record needs to implement IPrintWithWriter protocol and cljs.reader needs tag reader.

thheller13:10:32

better go with transit though

victorb13:10:49

@nickt otherwise pprint should be able to handle records

victorb13:10:13

team up with with-out-str to get a string version of it. (with-out-str (pprint my-record)

victorb13:10:43

although if you do read-string with pprint output you'll get a map back, not a record

nickt13:10:14

yea I get a map back from json too 😕

nickt13:10:18

definitely need the record

victorb13:10:44

yeah, you'll need tag readers then, and proper EDN

victorb13:10:11

^ has examples of how you can use Records+EDN together for de/serialization

nickt13:10:28

ok great, thanks. Does cljs have edn?

victorb13:10:37

@nickt yeah, ships with clojure core, available as clojure.edn , eh, but now when I think about it, not sure if it's included in cljs core actually. Only used cljs.reader/read with EDN in the past in cljs

yogthos17:10:48

I'm trying to use fullcalendar-react NPM module, but I get an error when trying to require it, looks like cljs compiler is trying to parse a CSS file that's required in one of the js files in the module, is there any workaround for this?

Errors encountered while trying to parse file
  node_modules/@fullcalendar/common/main.css
  {:line 4, :column 1, :message "primary expression expected"}
[:app] Compiling ...
[:app] Build failure:
Failed to inspect file
  node_modules/@fullcalendar/common/main.css

it was required from
  node_modules/@fullcalendar/common/main.js

p-himik17:10:01

I think you have installed a version of the package that requires additional building. You can install a prebuilt package with npm i fullcalendar - it should not have that problem.

thheller18:10:25

you can also set :js-options {:ignore-asset-requires true} so it just ignores the css

thheller18:10:37

but the css is also going to be missing 😉

yogthos18:10:32

ah thanks, let me play around with that

yogthos18:10:51

@U2FRKM4TW my understanding is that there's fullcalendar and fullcalendar-react, or does fullcalendar-react leverage fullcalendar?

yogthos18:10:18

currently, I've got

"@fullcalendar/core": "^5.3.1",
    "@fullcalendar/daygrid": "^5.3.1",
    "@fullcalendar/interaction": "^5.3.1",
    "@fullcalendar/react": "^5.3.1",
    "@fullcalendar/timegrid": "^5.3.1"

p-himik18:10:32

Did you install all those manually? If so, try removing all that and installing just fullcalendar. https://fullcalendar.io/docs/getting-started

yogthos18:10:06

so that's the non react version

p-himik18:10:59

I would try installing fullcalendar and @fullcalendar/react then. If that doesn't work, I'd try to figure out how that package works. Finally, if that doesn't make it clearer, I would go with the solution suggested by thheller above with a manual inclusion of all the styles and whatnot.

yogthos18:10:26

@U05224H0W is it possible to ignore assets for a specific module?

thheller19:10:26

doesn't matter if you ignore one or all. the build will just fail.

yogthos19:10:01

so adding :ignore-asset-requires does solve the problem with the error, but I was wondering if that might negatively affect other modules like say antd that include assets

thheller19:10:10

shadow-cljs does not support bundling any kind of "assets"

thheller19:10:48

I made the default to fail the build if any libs does this so you at least know

thheller19:10:14

so the only difference when ignoring is that it doesn't fail

thheller19:10:20

but you are not missing any files because of it

yogthos20:10:56

oh I see, thanks for the explanation sounds like I should be all set with that then

yogthos20:10:08

and I can just include the assets manually