Fork me on GitHub
#shadow-cljs
<
2020-08-26
>
souenzzo02:08:03

Hey I'm trying to load react-vega and I'm getting this issue

[:zubi] Build failure:
The required JS dependency "buffer" is not available, it was required by "node_modules/vega-loader/build/vega-loader.js".

Dependency Trace:
	zubi/dev.cljs
	zubi/client.cljs
	node_modules/react-vega/lib/index.js
	node_modules/react-vega/lib/Vega.js
	node_modules/react-vega/lib/utils/updateMultipleDatasetsInView.js
	node_modules/react-vega/lib/utils/updateSingleDatasetInView.js
	node_modules/vega-embed/build/vega-embed.js
	node_modules/vega/build/vega-node.js
	node_modules/vega-dataflow/build/vega-dataflow.js
	node_modules/vega-loader/build/vega-loader.js

Searched for npm packages in:
	/home/souenzzo/src/zubi/node_modules

See: 
I think that somehow vega-loader thinks that it's running on nodejs (maybe ssr) and tryies to import a buffer.

souenzzo02:08:27

I'm on thheller/shadow-cljs {:mvn/version "2.11.0"} Using "deps" both JVM8 and JVM14 do the same error.

thheller08:08:14

you need to npm install shadow-cljs in your project ...

👍 1
thheller08:08:31

which you should be getting a big fat warning about

souenzzo14:08:26

npm install --save-dev shadow-cljs and it do the hot-reoload even before I checkout logs/output Tnks for shadow-cljs ❤️

👍 1
royalaid03:08:14

@thheller would it be possible to a way to clear shadow-inspect?

royalaid03:08:53

Specifically remove any logged taps that are on the page

royalaid03:08:17

would be easier to read than (tap> "==================") 😂

thheller08:08:08

@royalaid please open an issue so I don't forgot to add it this time. working on the UI but need to solve something else first 😉

mkarp12:08:31

Hey there! With the following build config:

:app {:target :browser
      :js-options {:resolve {"foo" {:target :npm :require "foo"}}}}
Eval-ing the following code on the REPL:
(require '["foo" :as foo])
(js/console.log foo)
I get the following:
{__esModule: true, default: ƒ}
So to make an instance of foo, I have to call (foo/default.) Is there a way to specify within the build config that default should be “unwrapped” automatically, so that I can call (foo.)? What I’m trying to solve (and perhaps there’s a better way): There’s a dependency foo which exports a constructor function directly via a UMD. Within tests I need to substitute foo with a mock, so I’m using a separate npm package foo-mock which is an ESM and the constructor is under the default export property. The config in the end might look something like this:
:app {:target :browser
      :js-options {:resolve {"foo" {:target :npm :require "foo"}}}}

:test {:target :browser-test
       :js-options {:resolve {"foo" {:target :npm :require "foo-mock"}}}}
Thanks in advance!

thheller13:08:37

@me1676 why is the mock different from the actual? seems like a strange way to mock?

thheller13:08:15

you can try :resolve {"foo" {:target :npm :require "foo-mock$default"}} if you are on a recent version but I'm not sure that'll work

mkarp13:08:35

Yes, that’s an unfortunate decision by the author of foo-mock. I’ll try your suggestion

mkarp13:08:18

shadow-cljs 2.10.21 fails:

Build failure:
:resolve override for "foo" to "foo$default" which does not exist
{:tag :shadow.build.resolve/invalid-override, :require-from #object[java.io.File 0x4aa9328a ".../test.cljs"], :require "foo", :other "foo$default"}

thheller13:08:24

hmm yeah didn't expect that to work really 😛

thheller13:08:01

what are the packages?

thheller13:08:17

to answer your other question you can use (:require ["foo" :default foo]) and direclty use (foo.) or (:require ["foo$default" :as foo]) (new "standard" variant likely coming in next CLJS release)

thheller13:08:31

the only other suggestion I can make is publishing your own npm package that uses pusher-js-mock but exports the default you want

thheller13:08:10

module.exports.default = require("pusher-js-mock").Whatever;

thheller13:08:04

node_modules/pusher-js-mock-default/index.js or so

thheller13:08:14

then the :require redirect should be fine

mkarp13:08:35

Thank you @thheller, these are good suggestions!

neilyio20:08:46

How should I use a CommonJS/ES6 namespace in a ClojureScript macro? I'm following @thheller's https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html, which suggests that defmacro within a .`clj` file should use a fully-qualified namespace. But going by the shadow-cljs User Guide's https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages, I don't see how to use a fully-qualified namespace with CommonJS/ES6 imports, because they are referred to with strings as in (:require ["module-name"]).