chr15m / sitefox

Node + cljs backend web framework
https://chr15m.github.io/sitefox/
MIT License
283 stars 7 forks source link

Classpath lookup failed #16

Closed blogscot closed 2 years ago

blogscot commented 2 years ago

Hello,

I created new site-fox project as follows:

npm init sitefox-nbb mytempsite  

On opening VSCode, the warning message below appeared:

Classpath lookup failed when running clojure -A:test:dev -Spath. Some features may not work properly. Error: WARNING: Specified aliases are undeclared and are not being used: [:dev] Error building classpath. Library io.github.chr15m/sitefox has sha and tag that point to different commits

I seemed to be able to fix this issue by changing:

:deps
 {io.github.chr15m/sitefox {:git/tag "v0.0.1" :git/sha "b5520678b9fbf5919878a75750bb4d792c9eb8e2"}}

to

:deps
 {io.github.chr15m/sitefox {:git/tag "v0.0.2" :git/sha "86737d5de49d556e4b021575503eb64bc2ea6525"}}

After resolving this issue, I was able to Jack-In using nREPL (via deps.edn), however, evaluating expressions within server.cljs appears to do nothing.

chr15m commented 2 years ago

Hi @blogscot - and for reporting this issue. I just installed VS Code yesterday to test something so I'll see if I can replicate this today. What plugins should I install for Clojure, repl, etc?

blogscot commented 2 years ago

Hi @chr15m, I using:

Clojure CLI version 1.10.3.1087 Calva 2.0.257

Taken from the Output window, 'Calva says':

Calva is utilizing cider-nrepl and clojure-lsp to create this VS Code experience.
  nREPL dependencies configured:
    nrepl: 0.9.0
    cider-nrepl: 0.27.4
    cider/piggieback: 0.5.3
  clojure-lsp version configured: latest
...
clojure-lsp version used: 2022.02.23-12.12.12
clj-kondo version used: 2022.02.09

Investigating further: when I Jack-In, the output.calva-repl window shows that I'm in the user namespace. I can change namespace into my 'webserver' namespace, but it's broken.

clj꞉user꞉> 
(in-ns 'webserver)
#namespace[webserver]
clj꞉webserver꞉> 
(ns-map 'webserver)
; Syntax error compiling at (.calva/output-window/output.calva-repl:93:1).
; Unable to resolve symbol: ns-map in this context

Lastly, using 'Calva: Load Current File and Dependencies' results in

Capture d’écran 2022-03-25 à 12 02 53
blogscot commented 2 years ago

After further testing, I found that when I created an empty project and tried to evaluate 'Hello, World' in a file with extension .cljs nothing happened, however, if I changed it to .clj the REPL behaved as you would expect. Returning to my sitefox project, I saw no responses in the REPL when I evaluated expressions in server.cljs, but I did when I changed the extension to .clj. Like so,

...
clj꞉user꞉>  ; Use `alt+enter` to evaluate
; Jack-in done.
clj꞉user꞉> 
; Syntax error macroexpanding clojure.core/ns at (server.clj:1:1).
; ((:require ["fs" :as fs] [promesa.core :as p] [nbb.core :refer [*file*]] [sitefox.web :as web] [sitefox.html :refer [render-into]] [sitefox.reloader :refer [nbb-reloader]])) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form

I should really check Calva to see what known issues it has that might relate to this one.

chr15m commented 2 years ago

@borkdude do you know if there is a special way to get Calva to connect to the nbb repl instead?

borkdude commented 2 years ago

@blogscot Calva has special support for nbb, you can select the project type nbb in it.

Screen Shot 2022-03-26 at 22 51 49

But since Sitefox requires a --classpath setting, I recommend starting nbb's nREPL server on the command line like this:

DEV=1 nbb --classpath node_modules/sitefox/src/ nrepl-server :port 1338

And then select "Connect to a Clojure REPL > Connect to a running REPL in your project > nbb".

After that you should be able to evaluate forms in your sitefox project.

Screen Shot 2022-03-26 at 22 55 17
borkdude commented 2 years ago

I did get an error about a filewatcher dependency not being found, even after I tried to install it:

npm install filewatcher --save-dev

But that's another issue, unrelated to nREPL -- it also happens on the command line when running server.cljs.

$ DEV=1 nbb --classpath node_modules/sitefox/src/ server.cljs
Warning: env var SECRET is not set.
Deleting 8 routes
Warning: env var SECRET is not set.
Error while loading filewatcher.
Try: npm install filewatcher --save-dev
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'filewatcher' imported from /Users/borkdude/.nvm/versions/node/v14.18.0/lib/node_modules/nbb/out/nbb_core.js
    at new NodeError (internal/errors.js:322:7)
    at packageResolve (internal/modules/esm/resolve.js:687:9)
    at moduleResolve (internal/modules/esm/resolve.js:728:18)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:842:11)
    at Loader.resolve (internal/modules/esm/loader.js:89:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
    at Loader.import (internal/modules/esm/loader.js:177:28)
    at importModuleDynamically (internal/modules/esm/translators.js:114:35)
    at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
    at shadow_esm_import (file:///Users/borkdude/.nvm/versions/node/v14.18.0/lib/node_modules/nbb/out/nbb_core.js:5:41) {
  code: 'ERR_MODULE_NOT_FOUND'
}
borkdude commented 2 years ago

Ah, I know what the issue is. You need to invoke the local nbb module for this to work:

DEV=1 npx nbb --classpath node_modules/sitefox/src/ server.cljs
borkdude commented 2 years ago

What also works, from nbb version 0.3.1 on is this:

DEV=1 nbb --classpath node_modules/sitefox/src/ -e "(require '[\"filewatcher\"])"

instead of using js/import. Require is now allowed in non-toplevel positions, and if used like that, it returns a promise, like js/import does, but it will resolve from the local modules.

chr15m commented 2 years ago

Thanks @borkdude! So @blogscot you should be able to start an nrepl server to connect to like this:

DEV=1 npx nbb --classpath node_modules/sitefox/src/ nrepl-server :port 1338

I will discuss with @borkdude separately about whether there is a way I can start the nrepl server by default when starting the server.

blogscot commented 2 years ago

Thanks @borkdude and @chr15m, I managed to get the REPL hooked up. 👏 👏 👏

chr15m commented 2 years ago

@blogscot great stuff. What can I do to make this easier for people in the future? What about a Makefile rule that launches the repl server so you can go make repl or similar?

borkdude commented 2 years ago

Npm already has the scripts feature and this is already used in Firefox templates. Makefiles aren’t really portable and really just a C-build system feature. If you’re going to switch from npm scripts, may I suggest babashka tasks, which is the Clojure answer to makefiles?

https://book.babashka.org/#tasks

On Mon, 28 Mar 2022 at 06:55, Chris McCormick @.***> wrote:

@blogscot https://github.com/blogscot great stuff. What can I do to make this easier for people in the future? What about a Makefile rule that launches the repl server so you can go make repl or similar?

— Reply to this email directly, view it on GitHub https://github.com/chr15m/sitefox/issues/16#issuecomment-1080193831, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACFSBWEXDO5IXGFK6S2R3TVCE3VVANCNFSM5RRGBZCQ . You are receiving this because you were mentioned.Message ID: @.***>

-- https://www.michielborkent.nl https://www.eetvoorjeleven.nu

borkdude commented 2 years ago

Sitefox got autocorrected to Firefox on my phone :)

On Mon, 28 Mar 2022 at 08:13, Michiel Borkent @.***> wrote:

Npm already has the scripts feature and this is already used in Firefox templates. Makefiles aren’t really portable and really just a C-build system feature. If you’re going to switch from npm scripts, may I suggest babashka tasks, which is the Clojure answer to makefiles?

https://book.babashka.org/#tasks

On Mon, 28 Mar 2022 at 06:55, Chris McCormick @.***> wrote:

@blogscot https://github.com/blogscot great stuff. What can I do to make this easier for people in the future? What about a Makefile rule that launches the repl server so you can go make repl or similar?

— Reply to this email directly, view it on GitHub https://github.com/chr15m/sitefox/issues/16#issuecomment-1080193831, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACFSBWEXDO5IXGFK6S2R3TVCE3VVANCNFSM5RRGBZCQ . You are receiving this because you were mentioned.Message ID: @.***>

-- https://www.michielborkent.nl https://www.eetvoorjeleven.nu

-- https://www.michielborkent.nl https://www.eetvoorjeleven.nu

chr15m commented 2 years ago

@borkdude ah yes you're quite right, I forgot that I had used standard npm scripts in the create template, not a Makefile. I frequently use Makefiles in my own stuff but you're right that it does not make sense here.

blogscot commented 2 years ago

Hi @chr15m and @borkdude. I like the idea of providing npm scripts or bb tasks (which I need to read up on).

As you will have noticed from my earlier comments, I was confused regarding which of the myriad of Calva Jack-In points I was supposed to select so documenting the procedure that @borkdude explained above will go a long way to helping future visitors.