Fork me on GitHub
#shadow-cljs
<
2022-07-29
>
Daniel Gerson12:07:45

Firstly thanks for a great product! So I wanted to experiment with adding NPM lib react-native-logs to my react-native shadow-cljs project, so I yarn'd it, created a new namespace and added ["react-native-logs" :refer [logger]] but nothing I did could get logger to appear in the REPL (loading file or namespace) in a way that made sense. I thought maybe it was an ecma issue and tried react-native-logs$default, tried :as instead, but nothing worked. I got AssertionError Assert failed: (rc/valid-resource? rc)errors in the shadow-cljs console :thinking_face:. However it all worked perfectly if I used it from within the :app main namespace, or even required the new namespace from a linked one Obviously very unlike a Clojure REPL experience. I was wondering if it would be possible to give a hint in this scenarios so others don't suffer the hours it took me 😅

thheller12:07:33

dependencies cannot be added solely from the REPL in react-native

thheller12:07:55

that is because the code needs to be processed by the react-native metro build tool and it cannot see what you do at the REPL

Daniel Gerson12:07:04

Can shadow not see this attempt and warn the user?

thheller12:07:29

but I don't use react-native myself so maybe that check just does nothing and it blows up in other ways

thheller12:07:10

I mean what is AssertionError Assert failed: (rc/valid-resource? rc) and in which context did you get it?

thheller12:07:00

so far nobody has opened an issue about this so I assume everything is fine in react-native land 😉

😅 1
Daniel Gerson12:07:09

[2022-07-29 13:08:26.165 - WARNING] :shadow.cljs.devtools.server.util/handle-ex - {:msg {:op :cljs-compile, :input {:code "(cljs.core/load-file \"/Users/dmg46664/projects/samson/src/main/dimigi/network.cljs\")", :ns user, :repl true}, :include-init false, :call-id 5, :from 3}}
AssertionError Assert failed: (rc/valid-resource? rc)
	shadow.build.data/add-source (data.clj:220)
	shadow.build.data/add-source (data.clj:220)
	shadow.cljs.repl/repl-ns (repl.clj:325)
	shadow.cljs.repl/repl-ns (repl.clj:319)
	shadow.cljs.repl/process-read-result (repl.clj:504)
	shadow.cljs.repl/process-read-result (repl.clj:484)
	shadow.cljs.repl/process-input (repl.clj:647)
	shadow.cljs.repl/process-input (repl.clj:625)
	shadow.cljs.repl/repl-load-file* (repl.clj:281)
	shadow.cljs.repl/repl-load-file* (repl.clj:259)
	shadow.cljs.repl/repl-load-file (repl.clj:317)
	shadow.cljs.repl/repl-load-file (repl.clj:315)

thheller12:07:04

hmm didn't I fix that one? which version do you use? (its printed on startup)

Daniel Gerson12:07:24

Damn, I just realised I upgrade recently by changing the shadow dependency and not yarning the shadow upgrade 😬

thheller12:07:18

you can also set :version "2.19.8" in shadow-cljs edn if you want to be less reliant on npm/yarn stuff

thheller12:07:27

(only works if you don't use deps.edn/project.clj of course)

Daniel Gerson12:07:44

Oh, that's what I did, but in the edn file.

Daniel Gerson12:07:52

shadow-cljs - server version: 2.19.8 running at 

thheller12:07:22

well, yes with deps.edn the version is managed in deps.edn and package.json version doesn't really matter for compilation

thheller12:07:29

so you get that error with that version?

Daniel Gerson12:07:05

😅 yes get that error in that version... but before upgrading from 2.11.7 I got a little more out of the stacktrace:

"react-native-logs" - failed: simple-symbol? in: [:requires 3] at: [:requires] spec: :shadow.build.resource/require

thheller12:07:51

info from 2.11.7 doesn't help and just confuses the issue

thheller12:07:24

please open an issue with the above stacktrace and some info on how you got it

thheller12:07:34

I'll see about fixing that

Daniel Gerson12:07:48

Cool, I thought best here before opening an issue.

Daniel Gerson13:07:50

Oh, is it relevant that I'm using cider-nrepl as well?

thheller13:07:21

might be yes

tianshu13:07:23

Errors encountered while trying to parse file
  /home/tianshu/workspace/race-poker/racepoker-dapp/node_modules/lower-case/dist/index.js
  {:line 13, :column 13, :message "Character '̇' (U+0307) is not a valid identifier start char"}
Got some errors, the JS file is
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.lowerCase = exports.localeLowerCase = void 0;
/**
 * Source: 
 */
var SUPPORTED_LOCALE = {
    tr: {
        regexp: /\u0130|\u0049|\u0049\u0307/g,
        map: {
            İ: "\u0069",
            I: "\u0131",
            İ: "\u0069",
        },
    },
...
The reason could be shadow-cljs has its own identifier rules?

thheller13:07:15

no, that is a known error in the closure compiler. unfortunately nothing I can do about it

tianshu13:07:07

Ah, I see.

tianshu13:07:42

Can I patch this some how, I mean provide another file to overwrite this js

tianshu14:07:06

I changed the file in node_modules, then it goes to an infinite compiling status.

thheller14:07:57

don't know what that means. be careful when changing that file. you might leave invalid characters due to the non-visible unicode stuff

tianshu14:07:15

I just commented them. When the compiling can't complete, how can I investigate what's going on?

thheller14:07:40

what do you mean by "can't complete"? I can't see your screen so I cannot guess what you are doing

thheller14:07:55

any error during compilation should be logged somewhere

thheller14:07:26

if you use something like cider the error might be in some other hidden buffer or something

thheller14:07:48

I recommend running shadow-cljs in the terminal somewhere to ensure you see all output

tianshu14:07:09

Let me try it without cider

tianshu14:07:39

You are right

tianshu14:07:06

Now I see the errors

thheller14:07:43

yeah someone else reported a similar situation

tianshu14:07:47

Does it mean there's some malformed require

thheller14:07:01

maybe a have a similar cause? ie. changing the package folder name but not the package.json name?

tianshu14:07:23

Trying to understand the solution mentioned in this issue

thheller14:07:21

well if you answer my question that is also the solution 😛

thheller14:07:54

suppose you created a node_modules/my-lower-case and just copied the original package.json file there

thheller14:07:00

without updating the name field inside it

tianshu14:07:19

Hmm, nope. I just comment the content of that object definiation.

tianshu14:07:38

I didn't change anything else, on my refresh new installed node_modules

tianshu14:07:13

I'm sure it's caused by some packages, but I don't know which one it is. Because I introduce one package which bring me a lot dependencies

thheller14:07:57

do this then

tianshu14:07:27

Let me try

tianshu14:07:54

I can understand this code here, but it doesn't give me anything in the inspector. Nor it does with print instead of tap>.

tianshu14:07:40

shadow.user=> (alter-var-root #'shadow.build.npm/find-resource-in-package
  (fn [orig]
    (fn [npm package require-from rel-require]
      (try
        (orig npm package require-from rel-require)
        (catch Exception e
          (tap> [:what rel-require package require-from])
          (throw e))))))
#object[shadow.user$eval25371$fn__25372$fn__25373 0xead9010e "shadow.user$eval25371$fn__25372$fn__25373@ead9010e"]
shadow.user=> (shadow/compile :app)
[:app] Compiling ...
Execution error (AssertionError) at shadow.build.npm/find-resource-in-package (npm.clj:686).
Assert failed: (str/starts-with? rel-require "./")
shadow.user=> (alter-var-root #'shadow.build.npm/find-resource-in-package
  (fn [orig]
    (fn [npm package require-from rel-require]
      (try
        (orig npm package require-from rel-require)
        (catch Exception e
          (println [:what rel-require package require-from])
          (throw e))))))
#object[shadow.user$eval25784$fn__25785$fn__25786 0xa9377baa "shadow.user$eval25784$fn__25785$fn__25786@a9377baa"]
shadow.user=> (shadow/compile :app)
[:app] Compiling ...
Execution error (AssertionError) at shadow.build.npm/find-resource-in-package (npm.clj:686).
Assert failed: (str/starts-with? rel-require "./")

tianshu14:07:01

I think I did it the right way.

thheller14:07:26

hmm odd. looks correct.

thheller14:07:43

but again ... when in cider it is undefined where println goes

thheller14:07:13

when you run shadow-cljs clj-repl did it start a new instance

thheller14:07:20

or did it say "connected to server"

tianshu14:07:21

Now I'm using command line

tianshu14:07:42

Yep, it said "starting via clojure"

tianshu14:07:18

Thanks anyway, I think I got the idea. I can test more with this method

thheller14:07:36

which version do you use?

thheller14:07:00

hmm line number seems to match with the current. not sure why this wouldn't work

thheller14:07:41

I mean you can just (throw (ex-info "a more helpful error" {:package package}) e))

thheller14:07:46

instead of (throw e)

thheller14:07:08

but I mean println or tap should both be fine too

thheller14:07:29

I'll probably just add something like that given how unhelpful assert errors are

tianshu14:07:51

Hmm, I got some progress

tianshu14:07:29

I print the package before call the orig . But it shows me a package I used to have it in my project.

tianshu14:07:35

It's parrerell?

tianshu14:07:03

Hm, yes, it's a package which I had before. The rel-require here is

.-v2

tianshu14:07:17

It doesn't look like a require at all

tianshu15:07:36

😂So, there's one package call spl-token, and now there's a package called spl-token-v2. JS is Amazing

thheller16:07:53

hmm yeah I need to rewrite that code I guess 😛

thheller16:07:13

I just assumed that npm actually checks the name and stuff but I guess it doesn't