Fork me on GitHub
#shadow-cljs
<
2024-07-12
>
Eric Dvorsak08:07:38

I have an issue when I try to compile my code which requires a js file: In dev it all works fine: #?(:cljs ["/brian/formats/dividerBlot" :as dividerBlot]) but when I run: clojure -M:shadow-cljs release main I get:

[:main] Compiling ...
The required JS dependency "/brian/formats/dividerBlot" is not available, it was required by "brian/ui/rendering/text_field.cljc".

Dependency Trace:
	brian/client.cljs
	brian/model/session.cljs
	brian/ui_components/data_privacy.cljc
	brian/ui/rendering/text_field.cljc
the file is in src/js/brian/formats/dividerBlot.js my deps.edn: {:paths ["resources" "src/gen" "src/js" "src/main"] ...}

thheller08:07:23

looks fine. there is no difference in how these are looked up, so no clue what would cause this

thheller08:07:05

except maybe that the trace is brian/client.cljs. yet you pasted a snippet with a reader conditional, which are only valid in .cljc files?

thheller08:07:54

maybe there is an extra client.cljc somewhere that only included by another deps.edn alias?

thheller08:07:28

arg .. nevermind. got confused by my own trace logic 😛

thheller08:07:35

text field is cljc

Eric Dvorsak08:07:00

could it be source-paths vs deps.edn path?

thheller08:07:24

:source-paths in shadow-cljs.edn have no effect if deps.edn is used

Eric Dvorsak08:07:34

in my shadow-cljs.edn I have:

{:deps     {:aliases [:dev :rad-dev]}...}

thheller08:07:00

yep, then :source-paths or :dependencies have zero effect and are not used when using the shadow-cljs command

thheller08:07:40

but since that specifies other aliases I suspect there is just a difference in those aliases and the paths it constructs

thheller08:07:52

could be the :shadow-cljs alias has a :replace-paths? anything that would remove the default :paths really?

Eric Dvorsak08:07:12

there was a :paths ["src/main"]

Eric Dvorsak08:07:27

thanks that fixes it then!

👍 1
Eric Dvorsak08:07:08

while investigating I read that these js files are going to go through advanced compilation?

thheller08:07:24

depends on how they are written, but probable yes

thheller08:07:36

ESM import/export goes through :advanced

thheller08:07:47

CommonJS require/module.exports does not

Eric Dvorsak08:07:44

It contains this:

import Quill from 'quill';

const BlockEmbed = Quill.import('blots/block/embed');

class DividerBlot extends BlockEmbed {
  static blotName = 'divider';
  static tagName = 'hr';
}

Quill.register(DividerBlot);
I know little about how these js details, I only did this because it seemed almost impossible to convert this to clojurescript

thheller08:07:11

(ns foo.bar
  (:require
    [shadow.cljs.modern :refer (defclass)]
    ["quill$default" :as Quill]))

(def BlockEmbed (Quill/import "blots/block/embed"))

(defclass DividerBlot
  (extends BlockEmbed)
  
  (constructor [this]
    (super)))

(set! DividerBlot -blotName "divider")
(set! DividerBlot -tagName "hr")

(Quill/register DividerBlot)

thheller08:07:07

currently constructor is required, so if it has different arity you'd need to provide that

Eric Dvorsak08:07:10

I actually tried this after finding defclass with some research but it didn't work

thheller08:07:16

still need to add the no-constructor support for defclass

fabrao14:07:35

Hello @thheller, something strange is happening when I include this into deps.edn . com.google.protobuf/protobuf-java {:mvn/version "4.27.2"} .

--- SHADOW-CLJS FAILED TO LOAD! ----------------------

This is most commonly caused by a dependency conflict.
When using deps.edn or project.clj you must ensure that all
required dependencies are provided with the correct version.

You are using shadow-cljs version: 2.28.10

The important dependencies are:

  org.clojure/clojure "1.11.1"
  org.clojure/clojurescript "1.11.132"
  com.google.javascript/closure-compiler-unshaded "v20240317"

Please verify that you are loading these versions.
You can find all required dependencies here:

  

Please refer to the Guide for more information:

  

-----------------------------------------------------

The error encountered was:

Unexpected error macroexpanding proxy at (shadow/build/data.clj:83:3).

thheller16:07:47

nothing strange about it. the closure compiler depends on protobuf v3 and is not compatible with v4

👍 1
David Pham17:07:22

Hello, anyone managed to use the latest vega-lite 5.18.1 library? I can use the library until 5.15 but after that, I have a parsing failure from shadow-cljs

thheller17:07:42

sounds like they maybe introduced some syntax the closure compiler doesn't like

thheller17:07:55

thats unfortunately a bit common nowadays

David Pham17:07:53

Thanks. Any possible solution?

David Pham17:07:31

Which syntax might that be?

David Pham17:07:01

I see a #modified as a variable name

David Pham17:07:34

I guess I can try to recompile with ES6 as target

David Pham17:07:44

And not ES2020

thheller19:07:57

thats not relevant. there is no fix, as it fails to parse the file and cannot process it any further.

thheller19:07:43

#modified is syntax for private fields. that is indeed not supported.

thheller19:07:43

only option is to either not use that package or switch to use a different tool for JS processing, see https://shadow-cljs.github.io/docs/UsersGuide.html#js-provider-external