This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-29
Channels
- # announcements (4)
- # architecture (25)
- # babashka (23)
- # beginners (56)
- # boot (4)
- # calva (1)
- # cider (1)
- # cljs-dev (15)
- # clojure (135)
- # clojure-europe (4)
- # clojure-nl (21)
- # clojure-uk (61)
- # clojurescript (47)
- # community-development (4)
- # cryogen (11)
- # cursive (11)
- # data-science (11)
- # fulcro (25)
- # funcool (5)
- # graalvm (1)
- # graphql (4)
- # kaocha (4)
- # lambdaisland (20)
- # lumo (7)
- # meander (14)
- # off-topic (9)
- # pathom (2)
- # portkey (1)
- # re-frame (5)
- # reagent (53)
- # reitit (2)
- # ring (3)
- # shadow-cljs (32)
- # spacemacs (4)
- # sql (34)
- # testing (1)
- # tools-deps (3)
I am sending an index-handler on "/this-route":
(defn index-handler [req]
(assoc (resource-response "index.html" {:root "public"})
:headers {"Content-Type" "text/html; charset=UTF-8"}))
(def routes ["" {"/this-route" {:get index-handler}}]) ;; works
Which works fine.
But when I append anything to this-route, I'm unable to send index-handler even though I can still send a basic res/response:
(def routes ["" {"/this-route" {"" {:get index-handler} ;; doesn't work
"/something" {:get index-handler} ;; doesn't work
"/something-else" (res/response "some response") ;; works
}}])
I get the errors in the client side console showing an error in the index.html line, where I start my app:
<script type="text/javascript">myapp.system.go();</script>
and the error is "myapp is not defined."
Why might this be, and what am I doing wrong?index.html
<html lang="en">
<head>
<title>My App</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/style.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/png" href="favicon1.png"/>
</head>
<body>
<div id="app"></div>
<script src="js/compiled/myapp.js" type="text/javascript"></script>
<script type="text/javascript">myapp.system.go();</script>
</body>
</html>
Also:
DevTools failed to load SourceMap: Could not load content for : HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
@pshar10 do you have a myapp.system
namespace with a go
function defined and exported?
also does js/compiled/myapp.js
exists?
This is my myapp.system
(ns myapp.system
(:require [com.stuartsierra.component :as component]
[myapp.components.ui :refer [new-ui-component]]))
(declare system)
(defn new-system []
(component/system-map
:app-root (new-ui-component)))
(defn init []
(set! system (new-system)))
(defn start []
(set! system (component/start system)))
(defn stop []
(set! system (component/stop system)))
(defn ^:export go []
(init)
(start))
(defn reset []
(stop)
(go))
This is js/compiled/myapp.js
var CLOSURE_UNCOMPILED_DEFINES = {};
var CLOSURE_NO_DEPS = true;
if(typeof goog == "undefined") document.write('<script src="js/compiled/out/goog/base.js"></script>');
document.write('<script src="js/compiled/out/goog/deps.js"></script>');
document.write('<script src="js/compiled/out/cljs_deps.js"></script>');
document.write('<script>if (typeof goog == "undefined") console.warn("ClojureScript could not load :main, did you forget to specify :asset-path?");</script>');
document.write('<script>goog.require("devtools.preload");</script>');
document.write('<script>goog.require("figwheel.connect");</script>');
document.write('<script>goog.require("process.env");</script>');
document.write('<script>goog.require("cljs.user");</script>');
document.write("<script>figwheel.connect.start();</script>");
What exactly is your issue?
Recently you were trying to use shadow-cljs. Which build tool are you trying to use right now?
The exact issue is: When I go to a route like localhost:5000/myroute, which returns index.html it works. When I go to a route like localhost:5000/myroute/another and return index.html it doesn't work. The error is: myapp is not defined at line <script type="text/javascript">myapp.system.go();</script> But when I go to a route like localhost:5000/myroute/another, and return a res/response, it works.
@pshar10, I gave an answer to your question in #clojure. The "root" of the issue is absolute vs relative paths.
I don't know. I did lein new chestnut myapp, and did (go), and then (cljs-repl). This issue wasn't there before.
When I do (go), I see Figwheel: Stopped watching CSS Watcher paths ["resources/public/css"] Figwheel: Stopped watching build - app Figwheel: Stopping Websocket Server Figwheel: Starting server at http://127.0.0.1:3449 Figwheel: Watching build - app Compiling build :app to "dev-target/public/js/compiled/myapp.js" from ["src/cljs" "src/cljc" "dev"]... Successfully compiled build :app to "dev-target/public/js/compiled/myapp.js" in 0.93 seconds. Figwheel: Starting CSS Watcher for paths ["resources/public/css"] Started myapp on http://localhost:5000 :started
I would make sure that myapp.js
is even loaded when accessing your HTML file at myroute/another
A few months ago I think the cognitect team mentioned they don't usually use cider but some kind of inferior mode. Does anyone know what that setup is like? Are they configuring inferior-lisp or are they using inf-clojure?
I think Rich and Stu both use inferior-lisp but I’m not positive. I use Cursive mainly.
Ah that was it thanks! I'm trying to get spacemacs to play with lumo and wasn't sure if I could use inferior-lisp or inf-clojure.
Over the past couple of months I have used inf-clojure
with success. I have only been using it for hitting one keystroke to cause the previous form to be sent to, and evaluated in, a socket REPL. I haven't tried using it for other features like looking up docs, etc.
some useful ones for saving you some typing C-c M-r inf-clojure-reload
-- C-c C-b inf-clojure-eval-buffer
-- C-c C-r inf-clojure-eval-region
I typically rebind the ones I care about to function keys on my keyboard, as I detest using the Control key so often.
@U0CMVHBL2 Are you able to get inf-clojure expressions to print results in cljs? I've got a lumo repl running, I can eval forms, but I can't get the output from printing in a promise to display.
I haven't tried that. When you say "the output from printing a promise", is that some kind of expression you are trying to evaluate in the REPL? Or is it some kind of automatic printing as triggered by the some code delivering a value to the promise?
I do not use cljs very often. I have lumo
installed on a macOS system. Are you starting lumo
with a socket REPL (if that is even possible)? Or are you starting lumo
from Emacs?
Hmm, now I see lumo -h
shows that there is a --socket-repl
option to lumo
When I run this command in a terminal window: lumo --socket-repl 50505
Then in my Emacs window I use M-x inf-clojure-connect
with host localhost
and TCP port 50505
to connect to it, then copy and paste that expression (.then (.resolve js/Promise "hello") println)
into the Emacs buffer with the REPL prompt...
I see in the Emacs window the output:
cljs.user=> (.then (.resolve js/Promise "hello") println)
cljs.user=> #object[Promise [object Promise]]
cljs.user=>
In the terminal where I started lumo --socket-repl 50505
I see this output:
I did inf-clojure-connect, localhost, 55555, pasted that expression and nothing is printed
Lumo 1.10.1
ClojureScript 1.10.520
Node.js v11.13.0
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Exit: Control+D or :cljs/quit or exit
cljs.user=> (.then (.resolve js/Promise "hello") println)
cljs.user=> #object[Promise [object Promise]]
cljs.user=>
Did you check the REPL in the terminal where you started lumo to see if anything appeared there?
I don't know. Just knowing that it is in the terminal instead of the socket REPL is a clue that someone else may be able to take the ball and run with, though.
Found another path: Use the inf-clojure fn and the inf-clojure-generic-cmd var to launch a separate Clojure process in spacemacs. Now printed output shows up in that repl.
With socket repls, can they not handle side-effects like printing the results of a promise?