Fork me on GitHub
#shadow-cljs
<
2019-04-15
>
Marcin10:04:28

Heya, I have a problem using react-swipeable-views with shadow-cljs. When I go with yarn add react-swipeable-views it fails on the app start, giving me could not find module-entry: @babel/runtime/helpers/builtin/interopRequireDefault - most probably because that’s ES6 module. @thheller any clue on this one? I don’t want to use cljsjs lib for that.

ClashTheBunny13:04:07

ES6 modules have not been supported in the past, has that changed recently?

thheller14:04:08

@piczmar.rss that is most likely caused by a dependecy conflict. es6 modules are supported just fine.

thheller14:04:02

check the dependencies in node_modules/react-swipeable-view/package.json

thheller14:04:29

@babel/runtime and which one is installed in node_modules/@babel/runtime/package.json

thheller14:04:12

@clashthebunny ES6 modules have been supported for a long time

parrot 4
thheller14:04:46

@marcinszyszko I think its just the usual npm nonsense. the file node_modules/@babel/runtime/helpers/builtin/interopRequireDefault.js does not exist

thheller14:04:54

node_modules/@babel/runtime/helpers/interopRequireDefault.js does, so just without the builtin path. guess the path changed somewhere

thheller14:04:18

gotta love npm 😉

Marcin21:04:11

Thanks! Cleaning it up actually solved the issue 🙂

maxp14:04:21

@thheller could you help me with one thing that I did not understand well I'd like to build single :node-script that could be run without node_modules. I set {:js-provider :closure} but how to resolve built-in nodejs modules? like "fs" or "crypto"?

thheller14:04:37

:js-options {:js-provider :shadow :keep-native-requires true} is what you need

talgiat14:04:40

is there something like lein-ancient for shadow-cljs to check the project dependancies need to be updated?

thheller14:04:11

currently no

maxp15:04:10

@thheller thank you very much. But I had to install bufferutil and utf-8-validate - that stuff used in try { require(...) } ... no workaround here?

thheller15:04:54

not sure what you mean?

maxp15:04:28

there is such code in node_modeuls/ws/lib/BufferUtil.js `try { const bufferUtil = require('bufferutil'); module.exports = Object.assign({ concat }, bufferUtil.BufferUtil || bufferUtil); } catch (e) / istanbul ignore next / {

thheller15:04:45

do you use the ws package?

thheller15:04:06

oh right during development .. you probably want to add :keep-as-require #{"ws"} for development

thheller15:04:10

since that won't be in release builds

thheller15:04:15

still need to add that automatically

maxp15:04:28

not me, it installed in dependencies. as I understand. may be clj-http required it

thheller15:04:46

its shadow-cljs assuming you are using watch or compile?

maxp15:04:27

I use shadow-cljs watch and shadow-cljs server

thheller15:04:53

yeah just add :keep-as-require #{"ws"} then you should be fine

maxp15:04:44

Great! it Works!

maxp15:04:29

@thheller could you please explain to me how to add plain javascript file to the project build (not npm module).

maxp15:04:09

thank you

thheller15:04:33

if you can write the file in ES6 syntax though

thheller15:04:42

commonjs has some issues

thheller15:04:50

so import/export vs require

maxp16:04:36

if some one interested in building 'single executable js' there is working example - https://github.com/maxp/rss2tlg

talgiat16:04:49

@thheller I’m trying to run shadow with lein profiles, but running into problems. When you use lien with profiles do I need to add shadow in lein dependencies? also even if I do that I still run into issues.

thheller16:04:22

thats a dependency conflict on the closure-compiler dep

thheller16:04:52

the way lein deals with dependency conflicts is by picking whatever comes first

thheller16:04:09

so if anything has a dependency on clojurescript and thus closure-compiler it'll be picked

thheller16:04:20

even if shadow-cljs depends on newer versions

thheller16:04:25

so you need to resolve those conflicts

thheller16:04:23

should be fixed by adding these deps

[org.clojure/clojurescript "1.10.520"]
[com.google.javascript/closure-compiler-unshaded "v20190325"]
[org.clojure/google-closure-library "0.0-20190213-2033d5d9"]

thheller16:04:07

if you run through shadow-cljs.edn that is taken care of automatically

talgiat16:04:59

I’m not running the lein command, I’m running shadow-cljs just using lein with a profile to pull dependencies and paths (it’s really just for dependencies)

thheller16:04:35

then you are using the lein command

thheller16:04:49

or rather shadow-cljs is running it

thheller16:04:11

when you use :lein ... in shadow-cljs.edn the JVM is launched using lein

thheller16:04:19

so all its quirks apply

talgiat16:04:35

I see, yeah seem to be working now

talgiat16:04:09

The documentation says: “When executing directly via lein you must manually include the thheller/shadow-cljs artifact in your :dependencies. This is automatically added when launching via shadow-cljs.”

talgiat16:04:38

but I’m not doing that, so I found it a bit confusing that I needed to include shadow in the lien dependencies

thheller16:04:07

I'm also confused what you are doing exactly 😛

talgiat16:04:40

Since we’re using lein ancient to check for updates, I didn’t want to rewrite it for shadow

talgiat16:04:51

also we still use lein to build the server side code

talgiat16:04:22

So I thought I’d just put the client deps in the lein profile and pull them from there with shadow lein config

thheller16:04:22

so you are using :lein {:profiles ["foo"]} in your config?

talgiat16:04:56

:lein {:profile “client”}

thheller16:04:29

:profile is not a thing

thheller16:04:48

well regardless. IF :lein is a true-ish thing in shadow-cljs.edn

talgiat16:04:02

{:lein {:profile “+cljs”}

thheller16:04:04

nvm. I thinking of deps.edn

talgiat16:04:05

that’s from the doc

thheller16:04:12

yeah .. sorry got confused for sec

thheller16:04:33

so :lein {:profile "+cljs"} means that when you run shadow-cljs watch thing

thheller16:04:52

it'll execute lein run -m shadow.cljs.devtools.cli watch thing

talgiat16:04:00

I saw that

talgiat16:04:12

but you need shadow in the lein dependencies for that

thheller16:04:14

but it'll also run update-in [:dependencies] conj shadow-cljs or whatever the exact thing is

thheller16:04:31

so no you do not need to add shadow-cljs

thheller16:04:43

IF you run through shadow-cljs

thheller16:04:04

if you use lein normally it is better to add the shadow-cljs dependency manually

talgiat16:04:32

I still get: java.io.FileNotFoundException: Could not locate shadow/cljs/devtools/cli__init.class,

talgiat16:04:48

I ran: shadow-cljs compile app

talgiat16:04:15

watch is the same

thheller16:04:26

which lein version do you have?

talgiat16:04:33

good question

thheller17:04:10

hmm just add the shadow-cljs dependency

thheller17:04:30

the inject might not work and isn't really all that reliable anyways

thheller17:04:36

I'll check later

talgiat17:04:53

It all works when you add the dependancy

talgiat17:04:27

Might be good to think about plugin architecture so we can build stuff like lein ancient and the likes

thheller17:04:43

no need for plugins

talgiat17:04:49

As far as I understand plugin at the moment are just for watch process

thheller17:04:12

shadow-cljs run some.lib/ancient

thheller17:04:50

plugins are for things that need access to the runtime

thheller17:04:58

ancient wouldn't need that at all

thheller17:04:10

I'm going to build that eventually

thheller17:04:16

time is a factor there 😉

thheller17:04:38

it isn't much code to write that ... just something not high on my priority list

talgiat17:04:03

well it’s not really a plugin, just need access to shadow-cljs to read the dependencies key

talgiat17:04:13

it’s really just a slurp of a file

talgiat17:04:16

since it’s edn

thheller17:04:26

well you can just (slurp "shadow-cljs.edn") and get :depdendencies yeah

talgiat17:04:49

just didn’t want to rerwrite the whole ancient code again

talgiat17:04:54

Or copy it 🙂

talgiat17:04:10

Got actual features to deliver!

talgiat17:04:29

Another question, does devtools from one build target impact the other?

talgiat17:04:02

I have http-port and http-root in test build target but it seem to apply also when I watch app build target

thheller17:04:52

still supported in :devtools but yes they are all always started

thheller17:04:32

since otherwise the HTTP server wouldn't be available if you used shadow-cljs compile foo while the server instance is running

thheller17:04:41

I changed the config to make that more apparent

talgiat17:04:09

@thheller got it. Thanks for being super responsive, the clojure community needs more people like you.

❤️ 12
👍 8
martinklepsch18:04:50

The Clojure community also needs more people who allow people like Thomas to spend more time on their projects 🙂 http://patreon.com/thheller

👍 16
❤️ 12
parrot 4
Mno20:04:32

Well I’ve tried googling but it wasn’t particularly helpful

Mno20:04:05

Anybody know what to do when the (I’m guessing closure) compiler returns something like

Closure compilation failed with 1 errors
--- node_modules/vega-lite/build/vega-lite.js:8535
This code cannot be converted from ES6. extending native class: Array

Mno20:04:16

I was trying to use Oz, and I think I was managing to install the (cljsjs) dependencies correctly (npm install vega-lite and then creating the namespace (

(ns cljsjs.vega-lite
  (:require ["vega-lite" :as vega-lite]))

(js/goog.exportSymbol "VegaLite" vega-lite)
), I’m not sure where to start.

thheller20:04:41

@hobosarefriends maybe :compiler-options {:output-feature-set :es6} fixes it?

thheller20:04:54

if you can live with es6 output that is

Mno20:04:45

oh I tried :js-options {:language-out :ecmascript6}

Mno20:04:50

I’ll give this one a whirl

thheller20:04:24

@hobosarefriends try :output-feature-set instead, should be more reliable

Mno20:04:33

okidoke trying that.

Mno20:04:34

Well now I have another different issue, so I guess that worked

Mno20:04:44

Thanks mate.

Mno22:04:28

Is there a way to require a specific version of an npm package? (according to the package-lock I do seem to have both versions) in the namespace? (like :require ["[email protected]" :as vega-tooltip]