This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-24
Channels
- # announcements (39)
- # aws (4)
- # babashka (18)
- # beginners (32)
- # biff (10)
- # calva (22)
- # clj-kondo (11)
- # clj-on-windows (2)
- # cljs-dev (20)
- # clojure (31)
- # clojure-europe (130)
- # clojure-norway (21)
- # clojure-spec (24)
- # clojure-uk (17)
- # clojured (2)
- # clojurescript (6)
- # conjure (1)
- # core-async (5)
- # cursive (11)
- # datalevin (1)
- # datomic (9)
- # emacs (24)
- # figwheel-main (42)
- # fulcro (6)
- # gratitude (6)
- # honeysql (8)
- # juxt (16)
- # kaocha (6)
- # lsp (235)
- # malli (2)
- # nbb (7)
- # off-topic (23)
- # other-languages (24)
- # pedestal (7)
- # reitit (6)
- # sci (1)
- # shadow-cljs (21)
- # tools-build (22)
- # tools-deps (57)
- # vim (24)
Hi, I am a newcomer to Clojure ecosystem and this seems to be a favorite frustrating issue among users when someone tries to compile and run projects with shadow-cljs
=======================================================
BTW: kudos to all contributors of the project, hot-reloading feature in development is really awesome
=======================================================
shadow-cljs - Stale Output!
Your loaded JS was not produced by the running shadow-cljs instance. Is the watch for this build running
I am sharing some feedback on how you can reproduce this issue,
download https://github.com/fulcrologic/fulcro.git repository, then
make tests
make dev
shadow-cljs watch workspaces
It compiled and ran the module (workspaces) successfully at http://localhost:9002
Then I stopped the worker, (worker shutdown) and I tried to compile and run another module
shadow-cljs watch todomvc
I got the same port 9002 for the web app, it started watching build :todomvc and the build completed successfully but
When I tried to access the web URL, I got the previous project running and the red warning message informing me that this is a shadow-cljs - Stale Output! (see image attached)
I tried to refresh the page on the browser, clear the browser cache, remove folder (`.shadow-cljs`) none of these worked as a solution.
Therefore it seems there is a problem with the way things are configured and/or how shadow-cljs loads the generated JS code for the right module.
This is tree structure under the js folder
js
├── test
├── todomvc
│ └── cljs-runtime
└── workspaces
└── cljs-runtime
Each module generates a separate folder for JS, nevertheless with this https://gist.github.com/athanhat/ceaf406565013bd308395a5feea51c92#file-fulcro-shadow-cljs-edn it fails to redirect to the correct web app.
I had also a look at shadow-cljs server, it displays two active http servers at 9001 and 9002, but none of these redirects to the active build todomvc
the web page displays the workspaces
cards app with the infamous red warning message
Finally as a last resort I removed folder resources/public/js
and I executed again shadow-cljs watch todomvc`` . That worked although I got an empty web page for this module (probably I have to run some other server... don't know...)
OK I also had a quick look at your CLJS user guide, it seems that issue is not met anywhere in the manual. Perhaps it will help a lot if you add a section that explains how to avoid problems of this kind. It will also be good to suggest a better configuration, don't know, for fulcro project or projects with several modules in general.
> Then I stopped the worker, (worker shutdown)
☝️ this
With shadow-cljs watch ...
the browser app only works while the worker is running.
Yes I know, then I started again the worker with a different module, problem is that the worker doesn't clean previous state or redirect to the correct module.
In this case, I think it's because the resources/public/index.html
only loads workspaces
. https://github.com/fulcrologic/fulcro/blob/91fe23917d48eb7bfbe480eef2ed02ede3a4389b/resources/public/index.html#L17
If I'm not mistaken, regardless of which module you are watching, that is the index.html sent to the browser.
Nice catch, thanks Pieter, that certainly helps. So is it the case that someone has to change JS script address inside index.html
manually to run a different module in the project ? Is there configuration options for multiple index.html
files or a variable for the JS location ?
Sorry to be typical, but it depends. Eg Many deployed apps serve their index.html
dynamically and know which js to include with backend logic.
In this case, that specific index.html
is loaded from the browser. For developer in dev environment doing watch
this is probably ok(?)
Also read about release
build in the manual.
@U03ET6PDHCK I think you're supposed to go to the html for the build you're running
you can see how in the public folder, there is a todo.html
which has a script tag for the todomvc/main.js file built by the :todomvc
build
so if you go to localhost:9002/todo.html
you should see whatever output of the todo build is
all of this is very project specific config, the way that fulcro has it setup here isn't really typical, but also isn't strange. it just requires knowledge that isn't documented in the repo
Oh that is marvelous, thanks @U4YGF4NGM every little piece of information helps. I am bewildered with all these different project configurations in clojure(script) ecosystem.
In the same project/module (todomvc) another challenge is how to start the server src/todomvc/fulcro_todomvc/server.clj
.
If I am right, I have to start a local clojure REPL (I am using IntelliJ IDE), load the server code and do
(http-server)
(web/start @server)
But I am getting this error
cannot load server.clj file into the active REPL. It is not in scope for the module used to start the REPL
I guess this has to do with REPL configuration inside IntelliJ IDE, any suggestions to move on ?
BTW: Shouldn't server configured to start automatically with shadow-cljs, is there a way to do this ? Any relevant section in configuration files deps, shadow-cljs etc ?Ah, I think I found how to sort this out, in IntelliJ REPL Server configuration I chose to run with Deps and I also selected Clojure Deps Projects (dev, workspaces). So it seems server started but I cannot add item in the list. Failed to add item to server!
Is there something equivalent to closure-defines
for .clj
namespaces? I’d like to have a value that is configurable in shadow-cljs.edn
that is accessible in macro namespaces at compile time, but I don’t see anything in the documentation
you can do (get-in @cljs.env/*compiler* [:options :external-config :your-key])
which would give you the value of :compiler-options {:external-config {:your-key "foo"}}
from the build config
I've recently been switching projects over from figwheel, which has generally been going great. There was one convention it used that was helpful to me: dev builds would build to /target
and prod builds would build to /resources/public
. (Of course /target/
needed to be on the class path for dev builds, but I had a :dev
alias anyway so no big deal).
This was helpful because in the case of building a docker container on my local machine, it was easy to not end up with dev code in the container ... just don't copy it into the container.
It seems :output-dir
in a shadow-cljs.edn
build config controls both the build/watch
and the release
destination.
Is there a way to segregate these?
(It's not the biggest issue; it just means I need to add an rm -rf
to my bash docker build script. It's just slightly tedious since it pulls the dev JS out from any watch process I might have left running).
@rgm see https://shadow-cljs.github.io/docs/UsersGuide.html#_release_specific_vs_development_configuration. :output-dir "target" :release {:output-dir "resources/public"}