Fork me on GitHub
#shadow-cljs
<
2021-07-29
>
tianshu02:07:55

I fond the release build doesn't ship some unicode character correctly, (e.g. "◆"). I'm not sure it's an problem in closure compiler or in shadow-cljs.

thheller05:07:57

@mauricio.szabo as I said :exports can't be empty. so you must either add :exports or :init-fn for each module. the clue is the :empty-module warning which should really be an error I guess

thheller05:07:19

@doglooksgood neither. you probably just don't set the proper charset in your html. either your server can do so via Content-Type header or you can in your HTML directly via <meta charset="UTF-8">

tianshu05:07:01

@thheller I have meta tag, and problem only exists with advanced build in my case. (both dev and release use the same web server, handler and template file)

thheller05:07:51

and you didn't manually override the encoding in the build config to something like ascii?

thheller05:07:18

it defaults to utf-8 so it should be fine

thheller05:07:51

what can cause issues if you don't have the proper file encoding on the JVM side. it defaults to your OS default but sometimes runs into issues when your files don't use that encoding. if you use only shadow-cljs.edn you can set :jvm-opts ["-Dfile.encoding=utf8"] to force it. delete .shadow-cljs and restart it after setting set

tianshu05:07:21

Let me try more times, I'm not very clear yet. thanks for your explain!

tianshu05:07:38

Now my build works correct, I have no idea yet.

Otto Nascarella12:07:30

probably a stupid question…but here I go… anyone using :externs and :externs-file on their setup? how do you use it? any good docs I can refer to?

borkdude13:07:50

So I tried continuing with @mauricio.szabo's work. I cloned shadow locally (and installed it using lein install) and added a prn around the module-externs. I get:

$ clojure -M -m shadow.cljs.devtools.cli release modules
[:modules] Compiling ...
"var ex_tbd.core_eval_code;\nvar shadow_esm_import;"
Error processing externs:
JSC_PARSE_ERROR. Parse error. Semi-colon expected at externs.modules.js line 1 : 10

borkdude13:07:27

so it seems shadow isn't emitting some exported var correctly, perhaps?

borkdude13:07:10

(str "ex_" (cljs-comp/munge (name module-id)) "_" (name export-name))

mauricio.szabo14:07:41

Yes, having the same error even when adding :exports and/or :init-fn for everything...

borkdude14:07:20

the name is just mangled incorrectly, or perhaps it should create a nested object instead or so?

mauricio.szabo14:07:36

I tried to simply add:

:modules
                    {
                     :tbd.core {:exports {:eval_code tbd.core/eval!}}}
As a debugging step - same error happens

sheluchin14:07:15

I'm getting this error when connecting my editor to the REPL and I have no idea where to start troubleshooting it. I'm not sure this is the right channel to ask, but can anyone point me in the right direction?

thheller16:07:17

sorry this has nothing to do with shadow-cljs. I don't have a clue what is happening but it is something triggered by your REPL connection

sheluchin16:07:48

@thheller BTW, I notice that the shadow-cljs docs don't include vim-iced in the Editor Integration section, but the iced docs do have something: https://liquidz.github.io/vim-iced/#clojurescript_shadow_cljs. Not sure if this info is of any use to you 🙂 but thought I'd point it out.

thheller16:07:46

I don't even know what vim-iced is 😛

sheluchin16:07:29

It's a vim plugin to let you interact with your clj/cljs environment. Similar to Fireplace and growing in popularity. Anyhow 🙂

borkdude15:07:17

I replaced the dot with a dollar. I wasn't sure if this was the right thing to do, but at least it compiles now

borkdude15:07:28

(it doesn't run yet)

borkdude15:07:47

it seems the next obstacle is:

$ node out/tbd.main.js test.cljs
file:///private/tmp/tbd/out/tbd.core.js:1817
export { tbd$core as init-fn };
                         ^

SyntaxError: Unexpected token '-'

borkdude15:07:20

after manually "fixing" that, I stumble upon:

$APP.EB=this||self;
ReferenceError: self is not defined

borkdude15:07:45

and after removing self I get: ReferenceError: require is not defined in ES module scope, you can use import instead

borkdude15:07:18

any pointers how to properly fix the above are welcome.

thheller16:07:02

@borkdude yeah don't use dots in names that will be munged since dot is not munged

thheller16:07:11

as the error is telling you use import not require

thheller16:07:32

see the dynamic import thing I mentioned in the clojureverse post

borkdude16:07:34

@thheller What else should one write here then? :init-fn tbd.core/eval_code

thheller16:07:09

whats the context for that? where do you have that?

thheller16:07:49

if I look at the current config from the esm branch there is bunch of self-inflicted wounds 😛

thheller16:07:16

thats not valid at all

borkdude16:07:52

ok, thanks.

thheller16:07:32

{:tbd.core {:exports {:eval_code tbd.core/eval-code}}
 :tbd.main {:init-fn tbd.main/init
            :depends-on #{:tbd.core}}
 :tbd.reagent {:init-fn tbd.reagent/init
               :depends-on #{:tbd.core}}}

thheller16:07:36

something like that maybe

borkdude16:07:55

wasn't there a conflict between exports and init-fn?

borkdude16:07:09

I think the weird config may have been a result of that

thheller16:07:34

as I said yesterday you must have EITHER exports OR init-fn. not both. you had neither, there was an extra :main {:init-fn ...} that didn't belong there

borkdude16:07:00

do you mean per module or globally?

borkdude16:07:20

k, lemme try...

borkdude16:07:18

@thheller if I revert my "replace dot with dollar" workaround then I'm back at:

$ clojure -M -m shadow.cljs.devtools.cli release modules
[:modules] Compiling ...
:module-id "tbd.core"
"var tbd.core;\nvar shadow_esm_import;"
Error processing externs:
JSC_PARSE_ERROR. Parse error. Semi-colon expected at externs.modules.js line 1 : 7
Note that "var tbd.core;\nvar shadow_esm_import;" is the result of me printing bridge-name in esm.clj

borkdude16:07:54

should we use :tbd_core or so?

thheller16:07:17

just do not use dots

thheller16:07:27

they don't make sense in a node setting anyways 😛

borkdude16:07:46

@thheller ok, I'm back at the next error now:

ReferenceError: self is not defined
    at file:///private/tmp/tbd/out/tbd.core.js:591:428

thheller17:07:14

don't even use the tbd prefix. this isn't the browser so if a user is gonna import stuff they are going to import tbd/thing. tbd/tbd.thing doesn't do anything

thheller17:07:26

not going to comment on anything until all dots are removed 😛

thheller17:07:45

tbd.core.js

borkdude17:07:13

ok, that was the old file :)

borkdude17:07:29

$ node out/tbd_main.js
file:///private/tmp/tbd/out/tbd_core.js:591
$APP.CB=function(a,b){return dh(Kq.i(a,xs.h(Yk,$APP.Bk.g(kp)),b))};$APP.N2=function(a){for(var b=Kc($APP.Pj(a,new $APP.H(null,1,5,$APP.I,[$APP.wq],null))),c=a;;){var d=$APP.w(c);if($APP.p(d)){var e=d;d=$APP.z.i(e,0,null);e=$APP.z.i(e,1,null);b=Si.i(b,d,$APP.xe(e)?e:new $APP.m(null,1,[$APP.oq,e],null));c=zd(c)}else return new $APP.m(null,2,[$APP.xq,$APP.xq.g(a),$APP.$p,Mc(b)],null)}};DB=function(){return null};$APP.EB=this||self;ba="closure_uid_"+(1E9*Math.random()>>>0);da=0;var Wm=String.prototype.trim?function(a){return a.trim()}:function(a){return/^[\s\xa0]*([\s\S]*?)[\s\xa0]*$/.exec(a)[1]};$APP.g=pa.prototype;$APP.g.dc="";$APP.g.set=function(a){this.dc=""+a};$APP.g.append=function(a,b,c){this.dc+=String(a);if(null!=b)for(let d=1;d<arguments.length;d++)this.dc+=arguments[d];return this};$APP.g.clear=function(){this.dc=""};$APP.g.getLength=function(){return this.dc.length};$APP.g.toString=function(){return this.dc};var eh,fh,gh,Ba,Aa,ua,Mk,ya,sk,vd,Em,FB,Zh,dy,ok,xk,iD;eh={};fh={};$APP.md={};Ba=null;Aa=!0;ua=!1;Mk=!1;ya=null;sk=null;vd="undefined"!==typeof Symbol&&"function"===$APP.aa(Symbol)?Symbol.iterator:"@@iterator";
                                                                                                                                                                                                                                                                                                                                                                                                                                           ^

ReferenceError: self is not defined
    at file:///private/tmp/tbd/out/tbd_core.js:591:428

borkdude17:07:37

(I will be back after dinner)

thheller17:07:17

I think that self is from the newer closure library. try replacing it manually with globalThis

borkdude18:07:17

@thheller replacing self with globalThis got rid of the error. The next one is: > ReferenceError: require is not defined in ES module scope, you can use import instead I'm not sure where this comes from.

thheller18:07:59

do you use js/require somewhere?

thheller18:07:40

@borkdude shadow-cljs release modules --debug makes debugging much much easier

thheller18:07:51

do not use that require override you have there. not needed, just include with a relative path

borkdude18:07:09

the require override exposes js/require to the script user

borkdude18:07:23

so if they have local node_modules the script loads it from there as well

borkdude18:07:41

but I don't think the compiled JS uses it anywhere

borkdude18:07:49

I'll remove it just to make sure this didn't trigger it

borkdude18:07:23

ah, it came from the (js/require "fs")

thheller18:07:14

just use ["fs" :as fs] in the ns require

thheller18:07:47

but you may need to set :js-options {:keep-as-import #{"fs"}} in the build config

thheller18:07:55

since otherwise :esm will attempt to bundle it I think

borkdude18:07:45

(ns tbd.main
  (:require [tbd.core :as tbd]
            ["fs" :as fs]))
> The required JS dependency "fs" is not available, it was required by "tbd/main.cljs".

thheller18:07:39

did you set the keep-as-import?

borkdude18:07:29

yes also, tried it both without and with

thheller18:07:31

did you set it correctly? I mean in the correct place? needs to be in :js-options?

thheller18:07:46

the error you get suggests it wasn't properly set

borkdude18:07:13

oh crap you're right, the wrong build facepalm

borkdude18:07:41

looks like this works now! so apart from the self -> globalThis:

$ cat test.cljs
(prn :foo)
$ node out/tbd_main.js test.cljs
:foo

borkdude19:07:26

unfortunately the dynamic import is async, which makes it a bit more tedious to work with in scripts

borkdude19:07:59

but from the shadow-cljs side it seems this works now, many thanks

thheller19:07:02

btw I have a "use local node_modules over global node_modules" thing in shadow-cljs https://github.com/thheller/shadow-cljs/blob/master/packages/shadow-cljs/cli/runner.js

borkdude19:07:01

useful, thanks