Fork me on GitHub
#shadow-cljs
<
2022-06-24
>
Athan08:06:32

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.

👀 1
pieterbreed09:06:51

> Then I stopped the worker, (worker shutdown) ☝️ this With shadow-cljs watch ... the browser app only works while the worker is running.

Athan09:06:08

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.

pieterbreed09:06:40

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

👍 1
pieterbreed09:06:44

If I'm not mistaken, regardless of which module you are watching, that is the index.html sent to the browser.

Athan10:06:10

Nice catch, thanks Pieter, that certainly helps. So is it the case that someone has to change JS script address inside index.htmlmanually to run a different module in the project ? Is there configuration options for multiple index.html files or a variable for the JS location ?

pieterbreed10:06:41

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.

Athan10:06:40

I see thanks...

lilactown19:06:31

@U03ET6PDHCK I think you're supposed to go to the html for the build you're running

lilactown19:06:24

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

lilactown19:06:55

so if you go to localhost:9002/todo.html you should see whatever output of the todo build is

🙌 1
lilactown19:06:03

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

Athan11:06:44

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.

Athan12:06:50

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 ?

Athan12:06:38

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!

Joshua Smock10:06:18

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

thheller16:06:59

there is no equiv to :closure-defines in that regard. what do you intend to do?

thheller16:06:29

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

👍 1
rgm16:06:52

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).

rgm16:06:08

thank you! <makes mental note to make a carafe of coffee and spend the rest of the morning reading every word of the very good manual>