nextjournal / clerk-cljs-demo

A demo project showing a custom CLJS build for Clerk.
MIT License
4 stars 1 forks source link

Template is broken in various ways #4

Open Ramblurr opened 4 months ago

Ramblurr commented 4 months ago

Unfortunately this template is broken in various ways, it doesn't work out of the box like the README seems to suggest it would (though I could be misunderstanding).

More importantly however the nextjournal.clerk.static-app ns was removed here so it won't work with newer versions of clerk.

Ramblurr commented 4 months ago

It seems the static stuff isn't necessary for just running the notebook locally. To get it running locally I had to:

  1. Update the two clerk deps in deps.edn to ee0248bbc1054476e781e25b11414fa9899050b9
  2. Copy all of the dependencies from clerk's package.json to my own
  3. Remove nextjournal.clerk.static-app from shadow-cljs.edn
  4. Use clojure -A:dev to launch the repl

Then I was easily able to load cljs libraries (Quil in my case) in the cljs file and render them, very nice! :tada:

Unfortunately building the static app is still out of my reach. Running bb build-static results in

Execution error (StringIndexOutOfBoundsException) at jdk.internal.util.Preconditions$1/apply (Preconditions.java:55).

borkdude commented 4 months ago

Perhaps you can debug what is going wrong in subs, it could be an off-by-one error or so :)

Ramblurr commented 4 months ago

Yup, just did that. That's what I get for posting to github before troubleshooting myself.

The problem with subs was that the repo I was doing this from was git inited but had no commits, so it couldn't find the latest sha.

Now the static app is building, but fails to load in the browser:

Uncaught ReferenceError: nextjournal is not defined

image

I suspect that has to do with the changes in this commit that removed nextjournal.clerk.static-app

Replacing nextjournal.clerk.static-app with nextjournal.clerk.sci-env in shadow-cljs.edn didn't sort that out..

Ramblurr commented 4 months ago

Huzzah! It's working again.

After generating the template:

  1. Update the two clerk deps in deps.edn to ee0248bbc1054476e781e25b11414fa9899050b9 (which is the latest as of 2024-05-27)
  2. Copy all of the dependencies from clerk's package.json to the generated package.json
  3. Remove nextjournal.clerk.static-app from shadow-cljs.edn's :entries list
  4. Add nextjournal.clerk.sci-env and nextjournal.clerk.trim-image to shadow-cljs.edn's :entries list
  5. npm install
  6. Use bb clerk-watch and bb build-static

Step 2 is really quite unfortunate. @sritchie @zampino is there anyway around adding all the clerk npm deps to the project?

sritchie commented 4 months ago

@Ramblurr shadow should be doing that automatically for you, that's a bummer.

fwiw, this was my latest attempt at a template that tries to smooth over these edges: https://github.com/mentat-collective/clerk-utils/tree/main/resources/clerk_utils/custom

I haven't used the one in this project in a while so I'm not sure if the clerk-utils template will help. But give it a try as another option.