Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shadow-cljs] output lost when repl-ing node http server #3597

Open
harold opened this issue Dec 6, 2023 · 2 comments
Open

[shadow-cljs] output lost when repl-ing node http server #3597

harold opened this issue Dec 6, 2023 · 2 comments

Comments

@harold
Copy link
Contributor

harold commented Dec 6, 2023

Hi, thanks as ever for CIDER - we live inside it and it's amazing. I'm digging deeper into shadow-cljs and am getting hung up because my print output is getting lost in this one specific case...

Expected behavior

println produces output in the repl

Actual behavior

I cannot find my println output anywhere (:

Steps to reproduce the problem

When using shadow-cljs without CIDER, I eventually see the "INSIDE" printed:

$ npx create-cljs-project node-server-test
[snip...]
----
Done. Actual project initialization will follow soon.
----
$ cd node-server-test/
$ npx shadow-cljs node-repl
shadow-cljs - config: /home/harold/node-server-test/shadow-cljs.edn
shadow-cljs - updating dependencies
shadow-cljs - dependencies updated
shadow-cljs - server version: 2.26.2 running at http://localhost:9630
shadow-cljs - nREPL server started on port 36159
shadow-cljs - #4 ready!
cljs.user=> (defn handler [req res] (println "INSIDE") (.write res "Hello!") (.end res))
#'cljs.user/handler
cljs.user=> (require '["http" :as http])
nil
cljs.user=> (def s (http/createServer handler))
#'cljs.user/s
cljs.user=> (.listen s 8000)
#object[Server [object Object]]

;; Then, in another terminal:
$ curl localhost:8000
Hello!

;; And this is seen in the terminal repl:
cljs.user=> INSIDE

When doing the same thing in CIDER:

(cider-jack-in-cljs)
shadow
node-repl
;; Connected to nREPL server - nrepl://localhost:42703
;; CIDER 1.9.0 (Barcelona), nREPL 1.0.0
;; Clojure 1.11.1, Java 11.0.21
;;     Docs: (doc function-name)
;;           (find-doc part-of-name)
;;   Source: (source function-name)
;;  Javadoc: (javadoc java-object-or-class)
;;     Exit: <C-c C-q>
;;  Results: Stored in vars *1, *2, *3, an exception in *e;
;;  Startup: /usr/local/bin/npx shadow-cljs -d nrepl/nrepl:1.0.0 -d cider/cider-nrepl:0.41.0 -d cider/piggieback:0.5.3 server
;;
;; ClojureScript REPL type: shadow
;; ClojureScript REPL init form: (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/node-repl))
;;
To quit, type: :cljs/quit
[:selected :node-repl]
shadow.user> 
cljs.user> (defn handler [req res] (println "INSIDE") (.write res "Hello!") (.end res))
#'cljs.user/handler
cljs.user> (require '["http" :as http])
nil
cljs.user> (def s (http/createServer handler))
#'cljs.user/s
cljs.user> (.listen s 8000)
#object[Server [object Object]]
;; And now in the other terminal curl works works again (: 
;; but the "INSIDE" print output is never seen :|
cljs.user> 

Environment & Version information

Emacs version

27.1

Operating system

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.1 LTS
Release:	22.04
Codename:	jammy

JDK distribution

$ java --version
openjdk 11.0.21 2023-10-17
OpenJDK Runtime Environment (build 11.0.21+9-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.21+9-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

Thanks in advance for your time and consideration, I am looking forward to developing this node app inside cider with shadow-cljs. 😄

@vemv
Copy link
Member

vemv commented Dec 7, 2023

Thanks for a nice report!

I'll check it out as time allows.

You might have luck with logging in the meantime. It would also be interesting because Cider Log could eventually support it.

(right now it wouldn't, because only a few JVM logging backends are supported. But if you use a specific, popular choice for node.js, we'll have a motivation to keep things growing)

@harold
Copy link
Contributor Author

harold commented Dec 7, 2023

Logging is a good idea, thanks for that. https://github.com/winstonjs/winston looks like a popular choice, so I'll investigate that.

Let me know if there's more I can do or provide to help figure out where the output is getting lost here.

Appreciate you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants