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?@p-himik I asked you to turn Slack notifications on high volume next to you when sleeping.
don’t let it happen again.
Aye aye captain.
Good for you on Vim. My Emacs addiction is a questionable one. The Boot crowd were Vim users, I noticed.
I have a question for you or @dpsutton though… I assume the cljs repl is evaluating in the browser, right?
or is it spinning up a node instance or something?
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…
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).
could be more of an Emacs integration thing.
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 @dpsutton’s screenshot.
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.
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
aha… works!!
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
gotcha!
I have been putting calls to -main
in comment blocks for inline evaluation, but that sounds better.
that template does weird stuff. it uses lein-shadow
, a plugin that (imo) just adds more layers to tooling for no real benefit
that template doesn't include react
, react-dom
and create-react-class
, all of which are necessary for shadow.
can i recommend lein new reagent demorf2 +shadow-cljs
over what you are using? and then add re-frame from there?
> 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.
Ah, you probably meant the way shadow-cljs works with cljsjs.
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
@dpsutton you can definitely recommend another template!
I will try that.
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…assuming you use emacs, how would you go about setting up an environment that allows you to evaluate code in a buffer?
I’ll admit, I’m fully confused these days by the options available.
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.
I never know whether I should jack in to just clj, or clj&cljs.
it seems like a lot of the demo projects are maybe not current.
unfortunately for me, lots of tutorials seem to use Calva, alas… maybe I should consider switching.
can you tell me the exact command you used to create your template?
lein new reagent demorf2 +shadow-cljs +cider
I added cider because I figured I needed it, but I’m pretty lost in the ecosystem now…
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.
i'm confused why you're talking about figwheel then
if you are using +shadow-cljs
works for me
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)
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
i hope that clears it up @macrobartfast
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.
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.
omg omg omg :star-struck:
It worked. I’m so completely grateful.
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
and I’m really grateful for the latter.
(as well as the former, of course)
getting a project running is often my stumbling block (granted, I use Emacs, which I guess makes it a bit more tricky)
but… long live Emacs!
Sorry I wasn't here to help, was asleep. But I use vim either way. :D
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?
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
> I don't need JSON specifically
why are you converting to JSON then?
I just need to get to a string representation
(and back)
and JSON seemed like the answer until I realized the fact that these objects are actually records is lost
most common and best option is https://github.com/cognitect/transit-cljs
for records you'll need to add a custom read/write handler but thats quite easy to do
or just pr-str
+ cljs.reader/read-string
works too
ah neat
(read-string (pr-str (Node. 1 2 3)))
that doesn't seem to work in my repl?
records need special attention
hm mind pointing me to some docs on that?
sorry busy. record needs to implement IPrintWithWriter
protocol and cljs.reader
needs tag reader.
better go with transit though
@nickt otherwise pprint
should be able to handle records
team up with with-out-str
to get a string version of it. (with-out-str (pprint my-record)
although if you do read-string
with pprint
output you'll get a map back, not a record
yea I get a map back from json too 😕
definitely need the record
yeah, you'll need tag readers then, and proper EDN
maybe https://www.compoundtheory.com/clojure-edn-walkthrough/ would help
^ has examples of how you can use Records+EDN together for de/serialization
ok great, thanks. Does cljs have edn?
@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
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
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.
you can also set :js-options {:ignore-asset-requires true}
so it just ignores the css
but the css is also going to be missing 😉
ah thanks, let me play around with that
@p-himik my understanding is that there's fullcalendar and fullcalendar-react, or does fullcalendar-react leverage fullcalendar?
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"
Did you install all those manually? If so, try removing all that and installing just fullcalendar
.
https://fullcalendar.io/docs/getting-started
so that's the non react version
this one's the react one https://fullcalendar.io/docs/react
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.
👍
@thheller is it possible to ignore assets for a specific module?
doesn't matter if you ignore one or all. the build will just fail.
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
shadow-cljs does not support bundling any kind of "assets"
I made the default to fail the build if any libs does this so you at least know
so the only difference when ignoring is that it doesn't fail
but you are not missing any files because of it
oh I see, thanks for the explanation sounds like I should be all set with that then
and I can just include the assets manually