shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
zendevil 2021-01-20T05:26:02.119400Z

I’m getting an error when importing and using a module

zendevil 2021-01-20T05:26:19.119700Z

Here’s how it’s imported:

zendevil 2021-01-20T05:26:19.119900Z

[“@react-native-community/cameraroll” :default CameraRoll]

zendevil 2021-01-20T05:26:28.120200Z

Here’s how it’s used:

zendevil 2021-01-20T05:26:41.120400Z

(. CameraRoll save (.-uri (<p! (. @!camera recordAsync))))

zendevil 2021-01-20T05:26:46.120600Z

Here’s the error:

zendevil 2021-01-20T05:27:20.121400Z

undefined is not an object (evaluating ‘shadow.js.shim.module$ $react_native-community$cameraroll.default.save’)

zendevil 2021-01-20T05:27:26.121600Z

How to fix this error?

thheller 2021-01-20T10:19:54.123Z

@ps same problem as always. it might not be :default it might be :as or :refer. [“@react-native-community/cameraroll” :as CameraRoll] or [“@react-native-community/cameraroll” :refer (CameraRoll)]

Karol Wójcik 2021-01-20T11:29:23.123200Z

Is it possible to modify: https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/build/api.clj#L114?

thheller 2021-01-20T11:33:28.123600Z

modify what? https://shadow-cljs.github.io/docs/UsersGuide.html#_compiler_cache ?

Karol Wójcik 2021-01-20T11:36:56.123900Z

cache-blockers

Karol Wójcik 2021-01-20T11:37:18.124Z

Ok got it!

Karol Wójcik 2021-01-20T11:37:25.124300Z

Thank you @thheller

2021-01-20T13:57:49.124700Z

There is like 5 seconds delay between i save the cljs file and shadow recompiling it.

2021-01-20T13:57:54.124900Z

How to make it shorter?

thheller 2021-01-20T13:59:22.125200Z

do you use macos big sur?

2021-01-20T14:22:51.125500Z

yes

thheller 2021-01-20T14:26:09.126100Z

yeah I heard reports that its a lot slower there since they removed some stuff basically all CLJ(S) projects used

thheller 2021-01-20T14:26:18.126400Z

ie. they broke hawk

valsen 2021-01-20T15:16:38.130300Z

Hi everyone, I’m setting up a fullstack project with deps.edn and shadow-cljs.edn, and I have a “clj” and a “cljs” folder in src. I want shadow-cljs.edn to manage the cljs dependencies, but they are not being recognized at all. If I set :deps true I can successfully manage them from deps.edn instead, but I would prefer not having to do that. Any ideas what I might be doing wrong?

valsen 2021-01-20T15:32:34.130400Z

Oh and here’s shadow-cljs.edn:

{:source-paths ["src/cljs"]
 :dependencies
        [[re-frame "1.1.2"]
         [reagent "0.9.1"]]
 :builds
        {:app {:target     :browser
               :output-dir "resources/public/js"
               :asset-path "/js"
               :modules    {:main {:init-fn wallet.core/init}}
               :devtools   {:http-root "resources/public"
                            :http-port 4200}}}
 :nrepl {:port 9000}}
and deps.edn:
{:deps {org.clojure/clojure {:mvn/version "1.10.1"}
        metosin/reitit {:mvn/version "0.5.10"}
        http-kit/http-kit {:mvn/version "2.5.0"}}

 :paths ["src/clj" "resources"]

 :aliases {:run {:main-opts ["-m" "wallet.core"]}}}

thheller 2021-01-20T17:12:31.131100Z

looks fine. what is the problem?

Jp Soares 2021-01-20T17:53:28.131900Z

Is there a way to use the compiler option {:warnings-as-errors true} with cljs.js/eval-str? It looks like the available options of [cjs.js/eval-str](https://cljs.github.io/api/cljs.js/eval-str) are limited.

(defn evaluate [s callback]
  (cljs.js/eval-str
    compile-eval-state
    s
    nil
    {:eval cljs.js/js-eval
     :load (partial shadow.bootstrap/load (analyzer/empty-state))
     :warnings-as-errors true
     :context :expr}
    (fn [result] (do (js/console.log result)
                     (callback result)))))
I also tried to pass compiler-options as an argument of analyzer/empty-state but I had no success.

thheller 2021-01-20T18:03:21.133Z

no, that is a shadow-cljs feature not part of regular cljs

Jp Soares 2021-01-20T18:04:07.133600Z

hum.. ok, but I also tried the :warning-handlers and it also didn't work.

thheller 2021-01-20T18:05:32.134700Z

sorry can't help with self-host questions much. can't expect shadow-cljs features to work there since that is using all the regular cljs compiler stuff without any of the shadow-cljs additions/tweaks

Jp Soares 2021-01-20T18:06:45.135200Z

Thanks.. maybe the #clojurescript would be a better channel for this question?

thheller 2021-01-20T18:07:22.135600Z

probably

fsd 2021-01-20T19:35:03.135900Z

Hi There, I have shadow.cljs application, when I run yarn build , it gives generates build file main.js. After linking the css and main.js to index.html it gives error on some of the assets file for ex png images. The css file background-image: url("/icons/square.png") these gives 404. Any help would be appreciated!

valsen 2021-01-20T19:51:40.136Z

@thheller My namespaces in src/cljs are not being recognized, and neither are the required dependencies, as you can see in this screenshot

thheller 2021-01-20T19:52:52.136700Z

I guess you are looking at the file without an http server? just opening the index.html?

thheller 2021-01-20T19:53:25.137Z

well thats a Cursive issue. not anything to do with shadow-cljs

valsen 2021-01-20T19:53:30.137200Z

valsen 2021-01-20T19:53:38.137600Z

ah ok, i see

thheller 2021-01-20T19:54:04.137800Z

Cursive doesn't support shadow-cljs.edn so it doesnt "see" the source-paths and dependencies

thheller 2021-01-20T19:54:25.138Z

only option really is to put everything into deps.edn

valsen 2021-01-20T19:55:02.138200Z

ok, will do that then. Thanks for the explanation!:)

fsd 2021-01-20T20:00:21.138600Z

Correct, index.html

fsd 2021-01-20T20:02:49.140500Z

after linking up all the file, everything loads main.js css file except background-image: url (“”)

valsen 2021-01-20T20:04:46.141Z

If anyone else looks at this thread and notices that I forgot to add :as reagent and :as re-frame in the requirements, that was just when I quickly prepared the code to demonstrate. The problem persists with correct requirements and is due to Cursive, like thheller explained:)

thheller 2021-01-20T20:04:49.141200Z

well by using a path like /icons/square.png it'll look at an absolute path for your file

thheller 2021-01-20T20:05:15.141800Z

so if you open /home/user/project/foo/index.html it'll look for /icons/square.png

thheller 2021-01-20T20:05:28.142100Z

which is not where you have the files very likely 😛

thheller 2021-01-20T20:05:42.142500Z

you can either use icons/square.png so the path is relative to the current file

thheller 2021-01-20T20:05:54.142900Z

or use an http server which you'll likely use/need anyways

fsd 2021-01-20T20:37:06.143800Z

I tried using this on both opening index.html and local server and did not work

thheller 2021-01-20T20:51:46.144200Z

well if you show me your config and setup I can tell you whats wrong

thheller 2021-01-20T20:51:54.144500Z

without that I'm guessing which helps no one