shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
wilkerlucio 2020-12-12T05:58:54.428200Z

hello, I bumped shadow in a project and now I'm getting this: Namespace imports (goog:some.Namespace) cannot use import * as. Did you mean to import d3 from 'goog:module$node_modules$d3$dist$d3_node';? Any idea why? The line it points out have this: import * as d3 from "d3";

thheller 2020-12-12T14:51:07.429600Z

@wilkerlucio should be import d3 from "d3", unfortunately the closure folks made that change in a strict way. cant' cheat anymore

wilkerlucio 2020-12-12T14:53:10.429800Z

thanks, that fixes it 🙏

p-himik 2020-12-12T15:04:35.431600Z

When I compile a small piece of code with

:target           :browser
                         :compiler-options {:output-feature-set :es6}
                         :js-options       {:babel-preset-config {:modules "commonjs"
                                                                  :targets "chrome > 70"}}
there's always this small JS block in the result (after formatting it):
if ("undefined" !== typeof Symbol) {
        var c = Symbol;
        "object" != typeof c || !c || c instanceof Array || c instanceof Object || Object.prototype.toString.call(c)
    }
It doesn't seem to have any effect and I couldn't find where it comes from. Do you have any idea?

thheller 2020-12-12T16:57:03.431900Z

something in cljs.core. look for js/Symbol dunno why its not removed either.

p-himik 2020-12-13T10:23:12.439700Z

Nope, nothing there as well. Just 5 instances of js/Symbol usage and none of them seems to be the culprit.

GGfpc 2020-12-12T21:21:18.432400Z

So I've recently migrated to shadow-cljs in order to use NPM packages with reagent. I've managed to port over all my previous dependencies from cljsjs, but when I try to use this project: https://github.com/weknowinc/react-bubble-chart-d3 I get an error like this

Assert failed: Component must not be nil
I'm importing as such
(ns goodstats.stats
  (:require [reagent.ratom :as ratom]
            [reagent.core :as reagent]
            [ajax.core :as ajax]
            [clojure.edn :as edn]
            ["@weknow/react-bubble-chart-d3" :refer (BubbleChart)]
            ["recharts" :as recharts]))



(def BubbleChart (reagent/adapt-react-class BubbleChart))
In the README they say that one needs to import React as the component does not import it, but I assumed Reagent already imported react (since I'm using other react components). Does anyone know what I'm doing wrong?

GGfpc 2020-12-12T22:33:04.435Z

Also, in another dependency I have the following issue:

The required JS dependency "core-js/es6/math" is not available, it was required by "node_modules/recharts/lib/polyfill.js".

Dependency Trace:
        goodstats/index.cljs
        goodstats/stats.cljs
        node_modules/recharts/lib/index.js
        node_modules/recharts/lib/polyfill.js
index.cljs imports all others so I'm able to fix the missing dependency on all but index.cljs by adding the following to index.cljs
(:require ["core-js/es6/math"])
Resulting in this. And now I don't know how to proceed.
The required JS dependency "core-js/es6/math" is not available, it was required by "goodstats/index.cljs".

Dependency Trace:
        goodstats/index.cljs

anonimitoraf 2020-12-12T22:33:28.435100Z

Is that :refer (BubbleChart) on purpose? Instead of :refer [BubbleChart]?

GGfpc 2020-12-12T22:34:14.435400Z

I got it from here

GGfpc 2020-12-12T22:34:26.435800Z

On the shadow-cljs start page

anonimitoraf 2020-12-12T22:36:38.436100Z

Ah. I just had a look at the npm page and it looks like BubbleChart is the default import So, try :default BubbleChart

GGfpc 2020-12-12T22:38:09.436300Z

I tried both suggestions and unfortunately the error persists

anonimitoraf 2020-12-12T22:39:01.436500Z

maybe try :as BubbleChart as well?

anonimitoraf 2020-12-12T22:39:20.436700Z

I remember having to do :as Blah when I thought I needed :default Blah

GGfpc 2020-12-12T22:39:50.436900Z

That was the first thing I've tried to no avail 🙂

anonimitoraf 2020-12-12T22:40:16.437100Z

I'd be interested to know how people go about debugging issues like this

anonimitoraf 2020-12-12T22:41:17.437300Z

one other thing to check is, maybe the import is fine but the issue is caused by something else. After importing it, can you do a (print BubbleChart)? Just to check if it really is nil

GGfpc 2020-12-12T22:49:37.437500Z

Hmm, it seems that it returns a function. The console log points to this

GGfpc 2020-12-12T22:55:11.437900Z

But in the REPL it's nil