Fork me on GitHub
#shadow-cljs
<
2021-07-08
>
awb9904:07:56

When I use "watch" I get no warnings. But with release, I get the following warning. I guess it should be reorted to cognitect:

awb9904:07:58

------ WARNING #1 - ----------------------------------------------------------- Resource: com/cognitect/transit.js:649:8 variable module is undeclared --------------------------------------------------------------------------------

awb9904:07:18

Or does tis have something with my app ?

awb9904:07:34

I have a advanced build issue:

awb9904:07:36

(defn render-math [dom-node data-js] (let [mathjax (.-MathJax js/window) ;options (clj->js options) options (.getMetricsFor mathjax dom-node true)] (-> (.tex2svgPromise mathjax data-js options) ; (.then (fn [math-node] (.appendChild dom-node math-node) #_(add-math-css)))))) (defn ^{:category :ui} math "displays mathematical formulas" [{:keys [data options]}] [render-js {:f render-math :data data}])

awb9904:07:13

.getMetricsFor gets removed, but it is used in "math" function (which is in bundel).

awb9904:07:41

I guess the passing of functions in a map is the culprit?

thheller05:07:25

do you not get an externs inference warning? or are you on an old version that didn't have that enabled by default yet?

awb9917:07:27

I am not getting an externs inference warning. In adanced compilation the js module functions disappear. I will investigate more when this happens.

thheller17:07:35

please describe how you determined that it "disappeared". Closure doesn't just delete code.

thheller05:07:10

don't know what you mean by "gets removed". you mean "gets renamed"?

thheller05:07:19

the transit warning you can ignore

haywood14:07:25

I have a dependency .jar that uses shadow-cljs for it’s dependency management, does that project need to also include a deps.edn with mirrored dependencies so the parent project fetches them?

haywood14:07:03

or mirror them in the project.clj, I’m not sure how nested dependency management works

thheller14:07:01

I don't understand the question. what do you mean by nested dependency management?

zendevil.eth18:07:07

I’m trying to run jest with shadow cljs, and this is my test config:

{:target  :browser-test
                :test-dir "target/test/"
                :autorun tr
which basically compiles to target/test/js/test.js, but when I run jest on test.js, it produces the following:
FAIL  target/test/js/test.js
  ● Test suite failed to run

    browser bootstrap used in incorrect target

      1449 |
      1450 |   if (!doc) {
    > 1451 |     throw new Error("browser bootstrap used in incorrect target");
           |           ^
      1452 |   }
      1453 |
      1454 |   var scriptBase = goog.global.window.location.origin;

      at Object.call (target/test/js/test.js:1451:11)
      at Object.<anonymous> (target/test/js/test.js:1582:3)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.43 s
How to fix this? This is the singular test file that’s being compiled:
(ns humboi.sum-test)

(defn sum [a b] (+ a b))

(test "adds 1 + 2 to equal 3"
      (fn []
        (.toBe (expect (sum 1 2)) 3)))

thheller18:07:59

jest is not a browser so :browser-test won't work

zendevil.eth18:07:17

so what would be the correct target type?

thheller18:07:40

probably none. I have never used jest so I have not written any code to support it

thheller18:07:49

others might have experimented but I don't know

zendevil.eth18:07:27

I have npm installed @testing-library/react, but I’m still getting the following: https://gist.github.com/zendevil/0f88020fa4c757f1fc3b664425c51a6d I have tried deleting node_modules

thheller18:07:30

well if you delete it then it can't be found?

thheller18:07:47

that is a node error. node cannot find that module. did you install it in the correct directory?

zendevil.eth18:07:40

what I meant was that I tried deleting node_modules and running npm install

zendevil.eth18:07:04

I ran npm install --save-dev @testing-library/react in the root of the project

zendevil.eth18:07:54

On browser-test target, a similar error:

[:test] Compiling ...
[:test] Build failure:
The required JS dependency "@testing-library/react" is not available, it was required by "humboi/core_test.cljs".

Dependency Trace:
	humboi/core_test.cljs

Searched for npm packages in:
	/Users/prikshetsharma/Desktop/humboi/node_modules

See: 

thheller18:07:40

well does it exist? there should be a /Users/prikshetsharma/Desktop/humboi/node_modules/@testing-library/react directory?

zendevil.eth18:07:10

it doesn’t exist (even after npm install) but does in the devDependencies in package.json

thheller18:07:32

and you are in /Users/prikshetsharma/Desktop/humboi?

thheller18:07:50

and it is in this /Users/prikshetsharma/Desktop/humboi/package.json?

thheller18:07:39

do you have npm in production mode? ie. not installing devDepenencies?

zendevil.eth18:07:30

removing from devDependencies and installing with --save works

zendevil.eth18:07:54

without manually removing from devDependencies, --save has no effect

zendevil.eth18:07:26

btw in a luminus app, lein test runs only the clj tests. Is there a way to run only the cljs tests?

thheller18:07:08

don't know. I have never used luminus

zendevil.eth19:07:04

in any project that has both clj and cljs tests, how does one run only the cljs tests?

thheller19:07:32

shadow-cljs compile test && node the-file-generated-by-node-test-build.js

zendevil.eth19:07:57

and what if the target is browser-test?

thheller19:07:00

you open the browser?

zendevil.eth19:07:49

the port specified in :devtools {:http-port isn’t connecting when opened in the browser

zendevil.eth19:07:46

does that mean that I have to spin another server on that port?

thheller19:07:55

is shadow-cljs running?

thheller19:07:29

no, you don't need to start a separate server. assuming the config is correct it should be running.

thheller19:07:51

npx shadow-cljs server or a running watch is needed. otherwise it won't be running

zendevil.eth19:07:15

yeah the test watch is already running

thheller19:07:44

so what is your config?

zendevil.eth19:07:55

{:nrepl {:port 7002}
 :builds
        {:app
               {:target     :browser
                :output-dir "target/cljsbuild/public/js"
                :asset-path "/js"
                :modules    {:app {:entries []}}
                :devtools   {:watch-dir "resources/public"
                             :preloads  [re-frisk.preload]}
                :dev        {:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}}
                :release    {}}
         :test {:target  :browser-test
                :test-dir "target/test/"
                :autorun true
                :devtools {:http-port 8081
                           :http-root "target/test/"}}}
 :lein  true}

zendevil.eth19:07:05

both watches are running

zendevil.eth19:07:24

and test is compiling without warnings

thheller19:07:26

looks fine but FWIW you should be using :dev-http https://shadow-cljs.github.io/docs/UsersGuide.html#dev-http

thheller19:07:47

:autorun is not an option for :browser-test

zendevil.eth19:07:32

8081 isn’t working

zendevil.eth19:07:38

can’t be reached

thheller19:07:48

so what does it say when you start shadow? how do you start it in the first place?

zendevil.eth19:07:08

I start it with cider

zendevil.eth19:07:45

It does give this error:

Execution error (AssertionError) at shadow.cljs.devtools.server.nrepl/shadow-cljs-repl (nrepl.clj:30).
Assert failed: (keyword? repl-env)

zendevil.eth19:07:49

in the very beginning

thheller19:07:15

can't help you with that sorry. I don't use or know cider

wilkerlucio23:07:58

hello, I'm trying to include a recent version of BlueprintJS (https://blueprintjs.com/docs) in a project, but seems like Shadow can't load the files there

wilkerlucio23:07:09

my first guess is because the code has Typescript in it

wilkerlucio23:07:27

but it also has a dist compiled version like "@blueprintjs/core/dist/core.bundle.js", I tried to load that but no luck

wilkerlucio23:07:00

is there a way to load this kindle of bundles with Shadow?

wilkerlucio23:07:17

when I try to load ["@blueprintjs/core" :as bp-core], it doesn't give any error, but the bp-core comes blank

wilkerlucio23:07:23

same when trying to require the bundled

wilkerlucio23:07:35

I tried reverting to a blueprint version I now worked before, but that seems broken now too, gonna try to find in which version of shadow it broke

wilkerlucio23:07:22

that's strange, I reverted the version of shadow and blueprint to ones I know that work in another project, but I'm still getting the same errors

wilkerlucio23:07:50

nevermind, the issue is completly something else, I'm loadingf require.js to load monaco and that was conflicting under window.require facepalm

wilkerlucio00:07:55

I'm trying to integrate Monaco editor (https://microsoft.github.io/monaco-editor), but loading it is a pain... just from shadow it doesn't load at all, and this AMD approach is conflicting with the shadow loader stuff

wilkerlucio00:07:57

would love to hear if anyone has a way around this

lsenjov00:07:08

We’ve dealt with something similar to this, our solution was making sure require came after loading the main.js (I think, it’s been a little while)

lsenjov00:07:28

Since require.js overwrites the window.require when it loads

lsenjov00:07:08

Although all our usage of the thing needing require was done through the using interop, rather than importing it in shadow

wilkerlucio00:07:55

thanks, I ended up doing the same, and loading requirejs itself via react hooks inside the component

wilkerlucio00:07:58

looks terrible, but works

👍 4
thheller06:07:23

haven't looked at monaco in a while. they used to have their completely custom loading mechanism that didn't follow any conventions and didn't even work with webpack or so

thheller06:07:39

don't know if thats still the case today or if they provide some kind of esm build maybe