Fork me on GitHub
#shadow-cljs
<
2023-12-19
>
tianshu04:12:30

Is it possible to tell shadow to do a recompile after an update of local dependency?

thheller07:12:33

if by local you mean deps.edn :local/root then it should automatically do that

tianshu09:12:38

Sorry, I mean the npm dependencies.

tianshu09:12:59

I knew the dependencies in deps.edn require a repl restart.

thheller10:12:02

touch node_modules/the-thing/package.json should do the trick

tianshu10:12:09

Thanks for the tip!

pez10:12:09

I fail getting cljs.repl utilities to work. The following works in a plain ClojureScript repl

cljs꞉user꞉> 
; Evaluating file: core.cljs
[]
cljs꞉main.core꞉> 
(try
  (require '[cljs.repl :refer [apropos dir doc find-doc print-doc pst source]])
  (catch :default e
    (js/console.warn "Failed to require cljs.repl utilities:" (.-message e))))
nil
cljs꞉main.core꞉> 
(doc doc)
:repl/exception!
;
; Execution error (TypeError) at (<cljs repl>:1).
; Cannot read properties of undefined (reading 'call')
Is it supposed to work? If I qualify the doc symbol, it works:
(cljs.repl/doc doc)
-------------------------
cljs.repl/doc
  nil
nil

thheller12:12:43

first of all a require in a try is not valid, require is a special form in the REPL and can only be used at the top level

thheller12:12:20

otherwise things should be ok, but not everything is going to work

thheller12:12:28

I think pst is broken

thheller12:12:31

doc should be fine though

pez13:12:33

Thanks. It works fine if I don’t have it wrapped in a try.

alexdavis15:12:08

I'm trying to usehttps://shadow-cljs.github.io/docs/UsersGuide.html#_module_exports to export some cljs functions and import them in a vanilla js project, it all works for a super simple example but when I try and export a function in a file with a lot of imports then I get this:

cljs_env.js:61 Uncaught Error: Namespace "shadow.js" already declared.
    at goog.provide (cljs_env.js:61:13)
    at js.js:11:1
The js code looks like
import { foo } from "../shadow-output/js/foo.js";

console.log(foo);
relevant shadow config is
...
 :builds {:app {:target :esm
                :compiler-options {:output-feature-set :es-next}
                :modules {:foo {:exports {foo app.core/foo}}}
                :output-dir "shadow-output/js"}}
and app.core
(ns app.core
  (:require
   [re-frame.core :as rf]))

(defn foo [a b] (prn a b (+ a b)))
Without the re-frame require it works as expected, and when requiring things like 'clojure.string' it also works

thheller15:12:02

thats usually the error you'd get if something is getting loaded twice

thheller15:12:08

which runtime is this with?

alexdavis15:12:12

I haven't set the runtime but I'm guessing it defaults to :browser? docs say only browser is supported

alexdavis15:12:48

I'm not sure I even want a runtime, I just want shadow to spit out js files and my js app will handle the web server/hmr etc

alexdavis15:12:30

I get the same error with

:runtime :custom

thheller15:12:56

I'm asking what runtime you are running the code in 😛

thheller15:12:12

node? browser?

thheller15:12:30

repro always helps, otherwise I'm just guessing along

alexdavis15:12:23

https://github.com/armincerf/shadow-esm-issue ok strangely the error is a different one but the end result is the same, if I import re-frame it stops working (I think other imports have the same effect)

thheller16:12:11

this is vite doing stuff

thheller16:12:28

no clue what it is doing but it is loading things twice

thheller16:12:47

might have more luck with :npm-module

thheller16:12:21

wait no nevermind

thheller16:12:23

it is working fine

thheller16:12:56

otherwise vite provides react and shadow-cljs does too

thheller16:12:18

you are not helping yourself with this npm run dev command

thheller16:12:39

vite seems to reset the console quite often and in the process throwing away all shadow-cljs output

thheller16:12:14

also vite and shadow-cljs are both reloading the code, which isn't great

alexdavis17:12:30

hmm yeah I think what I'm trying to do probably isn't a good idea, will have to rethink things...

Chicão01:12:13

this might help you @U7KPK060K i made this repo https://github.com/matheusfrancisco/poc.cljs-export-to-js to write something in clojurescript and run with nodejs and run into a react app.

alexdavis15:12:23

any idea whats going on? should I push this up to a repo?

diego.videco17:12:14

I am trying to load a .mjs file from an html script, however I get a MIME type error, because apparently the server needs to serve this file with a MIME type other than application/octet-stream , I believe it should be text/javascript . Is there a way around this, besides renaming the file extension?

thheller17:12:54

why does it matter that the extension is .mjs? the browser doesn't have any special behavior for that

thheller17:12:09

and which server are you using?

diego.videco17:12:16

I think I am just using the shadow-cljs server. It doesn’t really matter except for the fact that the library I am using provides .mjs files.

thheller17:12:57

and what library is that? I mean why are you including it via script tag?

thheller18:12:11

(and why not just rename it to .js?)

thheller18:12:48

I mean I can add proper mime types for .mjs for the shadow-cljs server, but since browsers literally don't care what extension you use it doesn't matter?

diego.videco18:12:08

yeah I can rename them, I just wanted to know if there would be a more straight forward way to avoid having to write a script that renames these files.

thheller18:12:10

or what is the error precisely

thheller18:12:29

what is the part after the ? in that url?

diego.videco18:12:41

libs/pdfjs/pdf.mjs?v=kCsG9N0xiZwKFrpo8t0Lb

diego.videco18:12:21

It’s not being manually set, not sure what is doing that, but I guess it’s to prevent the browser from cacheing those files

thheller18:12:23

shadow isn't setting that

thheller18:12:02

you can add thheller/shadow-undertow "0.3.4" to your dependencies

thheller18:12:04

that should fix it

diego.videco18:12:09

btw, the versioning maybe comes from posthtml