Fork me on GitHub
#shadow-cljs
<
2018-09-12
>
pepe08:09:45

Hi, is there way to add :closure.defines through shadow/release function API? I need staging and production release builds and cannot get my head around the configuration. Or is there some better way I do not see?

pepe08:09:08

Well I found archive from 2018-06-20 and yes I did not see it. So ignore previous message.

urbanslug17:09:44

There's a lib I'm trying to use which default exports a class like so export default class RotatedMarker extends Marker https://github.com/verdie-g/react-leaflet-rotatedmarker/blob/master/src/RotatedMarker.jsx#L5

urbanslug17:09:20

however, what's weird is I can't imports it via :default because I get a shadow require error error but with :as I don't get the error

urbanslug17:09:43

anyway short question is is there something different about importing a default export that is like that?

urbanslug17:09:57

Uncaught TypeError: Super expression must either be null or a function, not object
    at _inherits (react-leaflet-rotatedmarker.js:26)
    at react-leaflet-rotatedmarker.js:29
    at Object.shadow$provide.module$node_modules$react_leaflet_rotatedmarker$lib$react_leaflet_rotatedmarker (react-leaflet-rotatedmarker.js:28)
    at Object.shadow.js.jsRequire (shadow.js.js:85)
    at Object.shadow.js.require (shadow.js.js:111)
    at ken.utils.leaflet_map.js:4

thheller17:09:24

@urbanslug what is Marker? it is not defined anywhere in that file?

urbanslug17:09:28

One sec I fetch a link for where it comes from

thheller17:09:30

it seems to be missing an import

thheller17:09:46

this may be a closure bug?

urbanslug17:09:49

So sometimes it works like when I comment out the import of RotatedMarker and just call Marker

urbanslug17:09:56

but when I clean

urbanslug17:09:42

any idea how I can get around it? I could whip something up really fast if it'll help

urbanslug17:09:43

something with all the tools

thheller17:09:58

the error is not from react-leaflet

thheller17:09:12

ok its not a closure bug. the file is just packaged badly

thheller17:09:01

I don't see how this code can ever work?

thheller17:09:13

it has the imports in the original sources

thheller17:09:40

oh no wait .

thheller17:09:48

I read the code wrong 😛

thheller17:09:35

@urbanslug "but when I clean" what does this even mean?

thheller17:09:07

I think this may just be incompatible version wise or so?

thheller17:09:30

the problem is that react-leaflet marker is a react element not a class

thheller17:09:50

they all seem to be

urbanslug17:09:18

When I run shadow-cljs clean

urbanslug17:09:25

Sorry I have a bad connection

thheller17:09:39

that command doesn't exist

urbanslug17:09:20

haha rm -rf target; rm -rf public/js;

urbanslug17:09:28

when I delete all compiled files

thheller17:09:01

well of course it fails if you remove all the files?

urbanslug17:09:13

then recompile

urbanslug17:09:51

Ok this is the process:

thheller17:09:22

it fails directly for me just be requiring it

urbanslug17:09:01

add ["react-leaflet-rotatedmarker" :default RotatedMarker] replace all Marker calls with RotatedMarker remove/comment out ["react-leaflet-rotatedmarker" :default RotatedMarker] and replace all RotatedMarker calls with Marker shadow-cljs recompiles reloads the page and it works as though I'm calling RotatedMarker clean then try again... rotation doesn't work

urbanslug17:09:19

> it fails directly for me just be requiring it Yeah I tried it in the REPL and it failed on me too

urbanslug17:09:48

which is why I thought the problem is related to the import

thheller17:09:48

you don't need all this to reproduce

thheller18:09:07

the error happens immediately when importing react-leaflet-rotatedmarker

urbanslug18:09:53

well but it magically works when it's commented out and shadow recompiles believe it or not.

urbanslug18:09:04

which is what's weird

urbanslug18:09:31

like what makes it suddenly work when it's commented out and RotatedMarker calls are replaced with Marker ones

thheller18:09:08

I don't understand? if you comment out the require then it will work yes? the require is what fails?

urbanslug18:09:16

if I comment the import out and revert RotatedMarker calls to Marker, rotation works in the dev server

urbanslug18:09:32

if I were to recompile it goes back to the old Marker

thheller18:09:25

I really don't follow what you are saying sorry

urbanslug18:09:19

well it's not deterministic tbh

thheller18:09:49

everything seems deterministic to me? it fails 100% of the time when I try to import react-leaftlet-rotatedmarker

urbanslug18:09:01

yes in a repl, no?

urbanslug18:09:21

in the browser it works sometimes

thheller18:09:27

oh .. forgot about the REPL if an import breaks

thheller18:09:42

it'll just have some weird lingering state or whatever

thheller18:09:36

so let me break down the problem

urbanslug18:09:00

Something like

(:require ["react-leaflet" :refer [Marker]]
          ["react-leaflet-rotatedmarker" :default RotatedMarker])

[:> RotatedMarker {...}]

thheller18:09:02

react-leaflet exports an object with many problems which look like they are supposed to be classes

urbanslug18:09:05

fails initially

thheller18:09:06

some of them are

thheller18:09:21

ie Map, MapComponent ...

thheller18:09:26

but Marker is just an object

thheller18:09:39

and class ... extends <object> is not valid

thheller18:09:44

that is what is failing

urbanslug18:09:55

save and recompile shadow does things and rotation works on Marker

(:require ["react-leaflet" :refer [Marker]]
          ;["react-leaflet-rotatedmarker" :default RotatedMarker]
          )

[:> Marker {...}]

thheller18:09:00

now I need to figure out if its a bug in shadow-cljs/closure that Marker is not a class

thheller18:09:46

typically I just jump into node to verify ...

thheller18:09:54

$ node
> require("react-leaflet")
ReferenceError: window is not defined
    at /mnt/c/Users/thheller/code/shadow-cljs/node_modules/leaflet/dist/leaflet-src.js:230:17
    at version (/mnt/c/Users/thheller/code/shadow-cljs/node_modules/leaflet/dist/leaflet-src.js:7:65)
>

urbanslug18:09:55

that's cool too

thheller18:09:09

guess I need to webpack to verify instead

urbanslug18:09:03

I'm not sure what's going on anymore 🙂

urbanslug18:09:11

haven't tried to use leaflet in node

thheller18:09:39

I'm trying to verify if the error happens in shadow-cljs only or in webpack too

urbanslug18:09:45

fwiw react-leaflet works in the browser for me all the time but react-leaflet-rotatedmarker is what's weird

thheller18:09:21

like I said it may just be version incompatible but the error looks odd enough so it may be an actual bug

thheller18:09:29

gotta verify in webpack to be sure

thheller18:09:55

ok. I get the same error in webpack

thheller18:09:24

so its just not compatible. maybe react-leaflet changed something since react-leaflet-rotatedmarker was released

urbanslug18:09:58

I have "react-leaflet": "^2.0.1", and it expects "react-leaflet": "^1.7.8",

urbanslug18:09:11

it also uses a fairly old version of react

thheller18:09:11

guess thats it then

urbanslug18:09:26

Looking into it

thheller18:09:28

npm package "react-leaflet-rotatedmarker" expected version "[email protected]^1.7.8" but "2.0.1" is installed.

thheller18:09:33

shadow-cljs even warned about that

urbanslug18:09:04

I didn't see that warning

urbanslug18:09:23

but I just downgraded to 1.9.1

thheller18:09:27

yeah its too easy to overlook currently 😉

urbanslug18:09:27

and it works

thheller18:09:36

I also didn't see it until I looked for it

urbanslug18:09:54

"cleaning" and checking to see if it'll still works

thheller18:09:33

you absolutely never need to clean

thheller18:09:46

besides what you are cleaning doesn't actually remove the cache

urbanslug18:09:06

hahaha wow really?

thheller18:09:19

the cache is in .shadow-cljs/builds

thheller18:09:25

you are only cleaning the output

thheller18:09:42

which is ok but wouldn't fix a cache problem if there was one

thheller18:09:14

but there hasn't been a cache related issue in a while now

urbanslug18:09:51

So all of this was a placebo? I could've sworn it had an effect

thheller18:09:13

hehe no effect on the compiler no

urbanslug18:09:19

one of those unplug the flash drive safely

urbanslug18:09:18

Thanks for your help btw. The problem was really simple but I don't know if I could've figured out because I didn't expect that to be the problem.

urbanslug18:09:48

yup it works