Fork me on GitHub
#shadow-cljs
<
2020-09-29
>
Jeremy03:09:21

Hi everyone. May I please get some advice on how to debug an AssertionError Assert failed: (rc/valid-resource-id? src-id) shadow.cljs.devtools.server.worker.impl/eval17300/fn--17303/fn--17306 (impl.clj:808) error? :shadow.cljs.devtools.server.util/handle-ex reports {:msg {:op :cljs-load-sources, :sources [[:shadow.build.classpath/resource "common/lists.cljc"]... and :sources seems to include a nil which I presume is causing the problem. Unfortunately I can't quite work out what's causing the nil.

Jeremy03:09:53

(The error happens when I try to evaluate anything once connected to the browser cljs repl)

thheller06:09:07

@clojure475 what are you trying to eval? and please do not shorten errors. I need the full stacktrace to make sense of it

Jeremy10:09:05

Thanks for reply Thomas. It seems to happen when I try to eval anything, even a plain keyword.

Jeremy10:09:45

The setup is a bit complicated (`shadow-cljs.edn` pointing at deps.edn aliases etc) but has been working brilliantly until I made too many changes without testing stepwise.

Jeremy10:09:54

Output

:a
[2020-09-29 20:04:36.176 - WARNING] :shadow.cljs.devtools.server.util/handle-ex - {:msg {:op :cljs-load-sources, :sources [[:shadow.build.classpath/resource "common/lists.cljc"] [:shadow.build.classpath/resource "common/allocations.cljc"] [:shadow.build.classpath/resource "test/tools.cljc"] [:shadow.build.classpath/resource "test/examples.cljc"] [:shadow.build.classpath/resource "test/common/allocations.cljc"] [:shadow.build.classpath/resource "test/common/api.cljc"] [:shadow.build.classpath/resource "test/common/appointments.cljc"] [:shadow.build.classpath/resource "test/common/dates.cljc"] [:shadow.build.classpath/resource "test/common/fsm.cljc"] [:shadow.build.classpath/resource "test/common/lists.cljc"] [:shadow.build.classpath/resource "test/common/message.cljc"] nil [:shadow.build.classpath/resource "test/common/core.cljc"] [:shadow.build.npm/resource "node_modules/react/cjs/react.production.min.js"] [:shadow.build.classpath/resource "test/client/events/requests.cljs"] [:shadow.build.classpath/resource "test/client/core.cljs"] [:shadow.build.npm/resource "node_modules/scheduler/cjs/scheduler.production.min.js"] [:shadow.build.npm/resource "node_modules/react-dom/cjs/react-dom.production.min.js"] [:shadow.build.npm/resource "node_modules/scheduler/cjs/scheduler-tracing.production.min.js"] [:shadow.build.npm/resource "node_modules/react-is/cjs/react-is.production.min.js"] [:shadow.build.npm/resource "node_modules/prop-types/factoryWithThrowingShims.js"] [:shadow.build.classpath/resource "cljs/user.cljs"]], :call-id 5, :from 57}}
ExceptionInfo no output for id: [:shadow.build.classpath/resource "test/examples.cljc"] {:resource-id [:shadow.build.classpath/resource "test/examples.cljc"]}
	shadow.build.data/get-output! (data.clj:197)
	shadow.build.data/get-output! (data.clj:193)
	shadow.cljs.devtools.server.worker.impl/eval17300/fn--17303/fn--17306 (impl.clj:813)
	clojure.core/map/fn--5866 (core.clj:2753)
	clojure.lang.LazySeq.sval (LazySeq.java:42)
	clojure.lang.LazySeq.seq (LazySeq.java:51)
	clojure.lang.RT.seq (RT.java:535)
	clojure.core/seq--5402 (core.clj:137)
	clojure.core.protocols/seq-reduce (protocols.clj:24)
	clojure.core.protocols/fn--8146 (protocols.clj:75)
	clojure.core.protocols/fn--8146 (protocols.clj:75)
	clojure.core.protocols/fn--8088/G--8083--8101 (protocols.clj:13)
Timeout while waiting for result.

thheller10:09:42

which version in deps.edn?

Jeremy10:09:35

2.11.2, running from clj not the command line

thheller10:09:21

try 2.11.4 just in case

thheller10:09:57

there was a bug related to this a while ago but no clue why you are still seeing it

thheller10:09:19

what REPL is this? assuming nrepl?

Jeremy10:09:05

yep nrepl and yep thank you the version bump (as well as restarting repl, which I do fairly frequently) seems to have resolved the problem!šŸ‘

šŸ‘ 3
pmooser07:09:09

In my project, I'm doing a normal + bootstrap build, and when I first launch shadow-cljs, I get a bunch of warnings about a provide conflict between the normal and bootstrap builds, like this:

[2020-09-29 09:40:52.675 - WARNING] provide conflict for #{goog.structs.Set} provided by web/js/bootstrap/js/goog.structs.set.js and {"/goog/structs/set.js" #{goog.structs.Set}}

pmooser07:09:25

Does this represent an error on my part, that can be avoided?

thheller07:09:08

don't have the output of a build on the classpath šŸ˜›

thheller07:09:44

although I thought I had fixed the filtering that should take care of this

thheller07:09:59

guess it doesn't account for bootstrap builds

pmooser07:09:56

So that's inferred or generated based on what, exactly? outdir-dir ? or asset-path ? I see no explicit classpath in my shadow-cljs.edn.

pmooser07:09:04

What I am doing seems to follow more or less the tutorials that exist.

pmooser07:09:21

So I don't find that advice of "don't do that" very easy to follow, unfortunately.

thheller07:09:54

by classpath I'm referring to your :source-paths and the :output-dir being on said source path

pmooser07:09:25

My :source-paths have my output dir on them - but if I remove it from source-paths and restart shadow-cljs, I get the same error.

pmooser07:09:48

Let's see ...

pmooser07:09:22

Ok, perfect.

pmooser07:09:47

So I ended up having that same issue in a project I was importing, which maybe seems to have been the source of the error.

pmooser07:09:58

Thanks for that - I'm not sure why my output dir was in the source paths to begin with.

pmooser07:09:05

Probably an artifact of something dumb I was doing long ago!

thheller07:09:51

well it is supposed to be filtered and ignored but it looks like it just doesn't filter bootstrap builds

thheller07:09:03

since the filtering is based on the cljs-runtime dir which bootstrap doesn't have

pmooser08:09:30

Ok, well, thank you for the insight in any case. I prefer having no warnings coming from the build if I can!

ullrich10:09:13

Intro and context: We are reusing some code between our web app and our react-native app and for that we need to do some runtime checks. Unfortunately we also need to convince the compiler to play along. For web itā€™s easy to stub out dependencies by using :js-options :resolve with :target :global. So here comes the question: If we want to use :target :global on react-native what is the best way to populate global? In our web app we can execute JS before the app runs, but on mobile I didnā€™t find a way to do so.

thheller10:09:51

@ullrich.schaefer do you have an example of what you are stubbing out this way?

thheller10:09:29

it isn't fully explained but I hope the idea is somewhat understandable

thheller10:09:43

point is that you don't do any "replacements" of the requires this way

ullrich10:09:38

A good example is Quill-js which is used in the main app to edit text. The mobile app is not concerned with editing text, but is including some namespaces that eventually end up importing quill. Also our main app is still build without shadow in production so weā€™re restricted in how we can import namespaces. There we use :global-exports in deps.edn. We use shadow for dev though so we can just do :js-options {:resolve {"quill" {:target :global :global "quill"}}} . Quill is just one of many examples and it would be great not to have to restructure all code around those dependencies, but find a solution at build tool level.

thheller10:09:00

I don't get it. where does quill come from?

thheller11:09:25

you might want to look into :js-provider :external if thats coming from webpack or so? only desribed here currently https://code.thheller.com/blog/shadow-cljs/2020/05/08/how-about-webpack-now.html#option-2-js-provider-external

šŸ‘ 3
thheller11:09:16

as far as I understand for the react-native issue though you can probably just set :js-options {:resolve {"quill" false}}

šŸ‘€ 3
thheller11:09:51

that will make it just ignore that dependency entirely? not sure if you need the actual global?

thheller11:09:51

I'm assuming that the code using the result isn't called at all?

thheller11:09:14

otherwise (:require ["quill" :as q]) the q will be false

ullrich11:09:50

Yes, thatā€™s actually what weā€™re looking for. Weā€™ll try that and Iā€™ll report back to you. Sorry, but our setup is a bit complicated and grew a bit over the years šŸ˜„ Our dependencies on web are loaded using an outdated approach called doublebundle, described https://presumably.de/double-bundle-integrating-npm-dependencis-into-clojurescript-projects.html. Certainly something we need to transition away from at some point. A lot of good things happened to the CLJS ecosystem over the last years. Shadow being one of them šŸ™ thanks3 šŸ™‡

ullrich12:09:04

@thheller Turned out it didnā€™t work because weā€™re not using shadow-style/double-quote imports (we have another app that is build using cljs with :target :bundle

thheller11:09:19

look into the :external stuff maybe

ullrich11:09:15

in which context? Do you have a link where I can learn more?

thheller11:09:29

see the link a few lines up

šŸ‘ 3
thheller11:09:06

for the web parts I mean

thheller11:09:46

thats basically a half-automated double-bundle

danielstockton11:09:47

Having some problems with my project after installing some npm dependencies Uncaught TypeError: Cannot read property 'hydrate' of undefined

danielstockton11:09:10

(ns pwa.core
  (:require [react-dom :as react-dom]
            [reagent.core :as r]))

danielstockton11:09:18

Why would react-dom be undefined here?

danielstockton11:09:52

Is the reagent dependency somehow conflicting with the react/react-dom in package.json?

thheller11:09:40

@danielstockton there is no use of hydrate in the code you pasted so no clue how you are using it?

danielstockton11:09:13

Sorry, just using it like this

(ns ^:figwheel-hooks pwa.core
  (:require [pwa.shared :as shared]
            [react-dom :as react-dom]
            [reagent.core :as r]))

(defn mount [el]
  (react-dom/hydrate (r/as-element [shared/root]) el))

thheller11:09:46

check if your node_modules/react-dom is empty for some reason

thheller11:09:59

sometimes that can happen with npm

danielstockton11:09:46

Yeah, these problems started after i installed html-react-parser for the server side part, which meant i also had to install react and react-dom with npm. Have tried clearing node_modules completely and reinstalling multiple times, npm installing the same version as reagent (16.13.0)

danielstockton11:09:06

ls node_modules/react-dom/
build-info.json  index.js  package.json  README.md          server.js       test-utils.js  unstable-fizz.browser.js  unstable-fizz.node.js
cjs              LICENSE   profiling.js  server.browser.js  server.node.js  umd            unstable-fizz.js          unstable-native-dependencies.js

danielstockton11:09:17

react-dom folder not empty

thheller11:09:25

if you haven't restarted shadow-cljs after running npm install or so maybe try doing that

šŸ‘ 3
Logan Powell21:09:55

I've been banging my head against Calva and VSCode with shadow all day and I'm spent... anyone know why when I eval a namespace nothing seems to get loaded?

Logan Powell21:09:17

here's my shadow-cljs.edn:

{:source-paths ["src"]
 :dependencies [[cljs-ajax "0.8.0"]
                [org.clojure/core.async "1.3.610"] ; ignored by shadow-cljs (embedded)
                [funcool/cuerdas "2.2.0"]
                [clojusc/defun "0.4.0"]
                [frankiesardo/linked "1.3.0"]
                [jamesmacaulay/cljs-promises "0.1.0"] ; FIXME: When batching cartography files: uncomment and `shadow-cljs pom`
                ;;[cider/cider-nrepl "0.23.0"] ; for Calva + Shadow-cljs 
                [net.cgrand/xforms "0.19.2"]]
 :nrepl        {:port 3333}
 :builds       {:lib {:target           :node-library
                      :output-dir       "public/census"
                      :output-to        "public/census/census.js"
                      :compiler-options {:optimizations :advanced
                                         :source-map-include-sources-content false}
                      :exports-var      census.core/census}
                :geo {:target           :node-library
                      :output-dir       "public/geo"
                      :output-to        "public/geo/batch_convert.js"
                      :compiler-options {:optimizations :simple}
                      :exports-var      configs.geojson.core/batch_convert}}}

Logan Powell21:09:45

... here's what I'm trying to load:

(ns configs.geojson.core
  (:require
   [cljs.core.async           :refer [>! <! chan promise-chan close! take! put! pipeline-async]
    :refer-macros [go go-loop]]
   [cuerdas.core              :refer [join]
    :as s]
   [clojure.set               :refer [map-invert]]
   [defun.core                :refer-macros [defun]]
   [cljs-promises.async       :refer [value-port]] ;; Fixme: Need this dependecy -< move configs to separate project
   [census.utils.core         :refer [map-target error err-type]]
   [configs.utils.core        :refer [read-edn FileSaver]]
   [configs.geojson.filepaths2018 :refer [paths]]
   [clojure.reader :refer [read-string]]
   ["fs" :as fs]
   ["shpjs" :as shpjs]
   ["mkdirp" :as mkdirp]))

(def geoKeyMap (read-edn "./src/configs/geojson/index.edn"))

Logan Powell21:09:09

and here's what's eval'd:

clj::shadow.user=> 
; Creating cljs repl session...
; Connecting cljs repl: shadow-cljs...
;   The Calva Connection Log might have more connection progress information.
; Connected session: cljs, repl: node-repl
; TIPS: You can choose which REPL to use (clj or cljs):
;    *Calva: Toggle REPL connection*
;    (There is a button in the status bar for this)
cljs::cljs.user=> 
; Evaluating file: core.cljs
; ------ WARNING - :redef --------------------------------------------------------
;  Resource: <eval>:16:1
 resolve already refers to: cljs.core/resolve being replaced by: cljs-promises.core/resolve
--------------------------------------------------------------------------------

nil
cljs::configs.geojson.core=> 
#object[TypeError TypeError: Cannot read property 'core' of undefined]
cljs::configs.geojson.core=> 

Logan Powell21:09:50

I've tried using a remote session and a straight "jack-in" workflow both using a build id as well as just a node-repl I get the same no matter

thheller22:09:18

@loganpowell the problem might be the warning

thheller22:09:43

I can't see what the REPL is actually doing (like what was eval'd) so I can't tell

thheller22:09:59

might be that the warning skips loading the code

Logan Powell22:09:51

let me try without defun

thheller22:09:19

defun? the warning is from cljs-promises? no clue what defun is?

Logan Powell22:09:30

sorry, that's what I meant

steveb8n22:09:46

Q: has anyone ever done aws interop to implement x-ray tracing for the entire SDK as documented here https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-nodejs-awssdkclients.html ? I canā€™t figure out the incantation for Shadow style interop

thheller22:09:03

what incantation?

thheller22:09:44

can't tell from the page since either example is missing code to understand what any of it means

steveb8n23:09:16

I agree. Thatā€™s part of my problem. Iā€™m experimenting with it now, looking at the generated js to try and match it up. Iā€™ll report back if/when I get it working

steveb8n23:09:52

(sorry, by ā€œincantationā€, I meant ā€œinterop formā€. thatā€™s me being too clever)

thheller23:09:10

yes but which form do you mean?

thheller23:09:35

var AWS = AWSXRay.captureAWS(require('aws-sdk')); that example doesn't explain where AWSXRay is coming from

thheller23:09:10

var ddb = AWSXRay.captureAWSClient(new AWS.DynamoDB()); that doesn't explain where AWS is coming from

thheller23:09:24

so I can't tell how this is supposed to be used

thheller23:09:22

unless its supposed to be used together

var AWSXRay = require('aws-xray-sdk');
    var AWS = AWSXRay.captureAWS(require('aws-sdk'));
    var ddb = AWSXRay.captureAWSClient(new AWS.DynamoDB());

thheller23:09:31

in which case the documentation is just plain weird

thheller23:09:51

but which part do you have an issue with?

thheller23:09:36

(ns foo.bar
  (:require
    ["aws-xray-sdk" :as aws-xray]
    ["aws-sdk" :as aws-sdk]))

(def aws (aws-xray/captureAWS aws-sdk))
(def ddb (aws-xray/captureAWSClient (aws.DynamoDB.)))

thheller23:09:50

maybe that helps. no clue what any of it does but that would be the translation

Logan Powell23:09:33

yep, resolve already refers to: cljs.core/resolve being replaced by: cljs-promises.core/resolve is the issue, when I remove that, smooth sailing. Is there a way to alias a function within a dependency like this?

steveb8n23:09:54

thanks @thheller I figured it out. the confusing part was around calling the ā€œnewā€ which is not very lispy. And yes, the AWS doc is not clear at all

steveb8n23:09:17

the solution isā€¦. use these 2 requires

["aws-sdk" :as aws-sdk-clean]                   ; clean means without x-ray
          ["aws-xray-sdk" :as aws-xray-sdk]
          
then use this form to wrap the sdk with xray
(let [capture-full-sdk (j/get aws-xray-sdk :captureAWS)]
  (capture-full-sdk aws-sdk-clean))
then you can use this let form to construct a service client where aws-sdk is the wrapped sdk
[s3-client (j/get aws-sdk :S3)
      s3 (new s3-client)]

steveb8n23:09:27

was not obvious but this works