Fork me on GitHub
#shadow-cljs
<
2017-12-28
>
Jon06:12:19

Shadow-cljs fails to import PIXI.js with ["pixi.js" :as [Pixi]]

mhuebert20:12:21

not sure if this is what’s causing your error, but :as should be a plain symbol, rather than a vector of symbols - eg. ["pixi.js" :as Pixi]

mhuebert20:12:40

(`:refer` expects a vector only because you can refer multiple symbols from a namespace)

Jon04:12:17

my bad, I pasted the wrong code. I was using :as Pixi.

Jon06:12:42

Uncaught TypeError: Cannot redefine property: default$
    at Function.defineProperty (<anonymous>)
    at index.js:23
    at Array.forEach (<anonymous>)
    at Object.shadow$provide.module$node_modules$pixi_js$lib$core$index (index.js:21)
    at shadow.js.require (VM2328 shadow.js.js:51)
    at Object.shadow$provide.module$node_modules$pixi_js$lib$index (index.js:19)
    at Object.shadow.js.require (VM2328 shadow.js.js:51)
    at phlox.main.js:10
(anonymous) @ index.js:23
shadow$provide.module$node_modules$pixi_js$lib$core$index @ index.js:21
shadow.js.require @ VM2328 shadow.js.js:51
shadow$provide.module$node_modules$pixi_js$lib$index @ index.js:19
shadow.js.require @ VM2328 shadow.js.js:51
(anonymous) @ phlox.main.js:10

mhuebert20:12:21

not sure if this is what’s causing your error, but :as should be a plain symbol, rather than a vector of symbols - eg. ["pixi.js" :as Pixi]

thheller21:12:03

hmm weird what pixi is doing there

thheller21:12:49

I define the default$ for cljs compat since cljs munges default to default$

thheller21:12:03

I can take that out for JS->JS requires though since they won't need that

thheller21:12:19

won't get to it until next week though

mhuebert21:12:13

hmm, what is it that Pixi is doing that causes this to choke?

thheller21:12:58

from the screenshot it is doing a forEach copying the properties from _math with was required above

thheller21:12:28

which it also did for _const

thheller21:12:44

since both have a default$ that blows up

thheller21:12:51

I think at least, didn't look at the actual code

thheller21:12:40

the code already skips the default property but it doesn't know about default$

mhuebert21:12:57

looks like that is caused by babel? in the repo we have:

export * from './math';
then in the published node_modules, that has been compiled to
var _math = require('./math');

Object.keys(_math).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function get() {
      return _math[key];
    }
  });
});

thheller21:12:19

yeah looks like babel

mjmeintjes21:12:33

Is it possible to specify the host ip for the dev server? I'd like the server to listen on 0.0.0.0 instead of localhost.

thheller21:12:17

@mjmeintjes yes :http {:host "0.0.0.0"} in the top level, same as :builds

thheller21:12:32

oh wait dev server

thheller21:12:53

I think I forgot to add the option for those

mjmeintjes21:12:34

Yeah, just tried it but it seems to only change the ip for the shadow-cljs server, not the dev server.

thheller21:12:58

yeah, it defaults to localhost and isn't configurable

mjmeintjes21:12:07

It would make sense to add a :http-host key under devtools?

thheller21:12:30

will fix it to use the main http :host config by default and :http-host in devtools

thheller21:12:03

you probably only want to configure it once so it would make sense to configure use the top level :host

mjmeintjes21:12:14

It is strange, but I used to be able to access the dev server from other machines in a previous version, but since I upgraded it seems to only listen on localhost.

mjmeintjes21:12:53

2.0.105 to 2.0.122

thheller22:12:26

oh that might be an unintended side effect of switching the http server

thheller22:12:50

removed aleph and switched to undertow recently to optimize startup time and get http2 support

mjmeintjes22:12:11

I see. No worries. Do you want any help adding the host option?

thheller22:12:56

I can take care of it if you don't mind waiting a few days

thheller22:12:14

pretty busy currently. should be next week.

mjmeintjes22:12:46

No rush. I'll see if I can figure it out and maybe create a PR.

thheller22:12:38

I could just switch the default to 0.0.0.0, seems way more reasonable

thheller22:12:53

don't really need to restrict it to localhost

mjmeintjes22:12:13

I agree regarding the default, especially since it was that way before. Thanks.

dominicm22:12:59

I was surprised to see undertow as a dependency of shadow, knowing there's a http server built-in makes more sense.

dominicm22:12:09

https://github.com/thheller/shadow-cljs/wiki/REPL#embedded-dev-only I'm trying to do this, it seems that shadow/start-worker is not in devtools.api. I tried watch but ran into an issue where runtime/instance-ref was not set, so I figure I'm doing something wrong.

thheller22:12:52

@mjmeintjes I pushed [email protected] which changes the default host back to 0.0.0.0

thheller22:12:28

@dominicm if you are using the embedded version you need to manage the runtime somehow

mjmeintjes22:12:40

Great! I love the fast release cycles you have. Thank you.

thheller22:12:43

(shadow.cljs.devtools.server/start!) to start and stop!

thheller22:12:30

start-worker is just dev the wiki is a bit old

thheller22:12:48

but it should still be there

dominicm22:12:20

@thheller start-worker got moved into a different namespace I think. There's a get-or-start-worker in api.clj

thheller22:12:11

indeed. I renamed that to watch to match the CLI

thheller22:12:59

the start! fn will launch the “runtime” which runs in a background thread(s)

thheller22:12:25

watch in particular needs that

thheller22:12:38

the others start a “light” runtime so they don’t need that

thheller22:12:09

can’t do with-runtime for watch since it needs to keep running in the background

dominicm22:12:53

Yeah, exactly. But I presume it covers all the steps I need to take?

thheller22:12:25

no with-runtime is not suitable for watch

dominicm22:12:53

I mean, it shows me the functions I need to call in order to do setup, no?

thheller22:12:58

no, it is a “light” runtime

dominicm22:12:20

I'll read start!, I'm not interested in using the shadow http server in this case.

thheller22:12:34

watch needs that to reload files though

dominicm22:12:51

Oh, why is that?

thheller22:12:21

the clients connect to a websocket for REPL/reloading

thheller22:12:38

that server is started by start! not by with-runtime

dominicm22:12:33

Is there a version which starts only the websocket server (or just the core requirements).

thheller22:12:34

with-runtime will use the server created by start! though so it won’t launch a new runtime

thheller22:12:33

if you don’t have any other http servers configured they won’t be started

thheller22:12:40

but yes the websocket server is a core requirement

dominicm22:12:55

Dec 28, 2017 10:36:35 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.6.Final
IllegalArgumentException XNIO001001: No XNIO provider found  org.xnio.Xnio.doGetInstance (Xnio.java:255)
Is this a known, common, mistake?

dominicm22:12:19

Hmm, looks undertow related

thheller22:12:57

never seen that before, probably a missing dependency

thheller22:12:25

are you on java8?

thheller22:12:55

I really don't recommend running shadow-cljs alongside all your other JVM stuff

dominicm22:12:10

I'm on java8, yes.

thheller22:12:12

too many headaches dealing with conflicts and such

dominicm22:12:48

I'm thinking it could be an issue with tools.deps.alpha not resolving dependencies correctly.

thheller22:12:25

if you have mvn installed you can clj -Spom and mvn dependency:tree

thheller22:12:40

maybe that has some useful info

dominicm22:12:10

❯ boot -d thheller/shadow-cljs -B with-cp --write --file /tmp/bootcpfile
Retrieving maven-metadata.xml from  (6k)
Retrieving shadow-cljs-2.0.124.pom from  (7k)
Retrieving xnio-nio-3.3.6.Final.pom from  (6k)
Retrieving shadow-cljs-2.0.124.jar from  (376k)
Retrieving xnio-nio-3.3.6.Final.jar from  (113k)
That's interesting.

dominicm22:12:44

Yeah, the boot classpath file has 2 entries for xnio, and tools.deps.alpha only has one.

thheller22:12:51

tools.deps definitely has some unresolved issues. there was another issue where it picked an ancient version of clojurescript over a more current one

dominicm22:12:56

Might be because the dependency has a scope sigh

thheller22:12:20

I think boot uses pomegranate which lein and shadow-cljs also use

thheller22:12:56

or basically all CLJ tools except tools.deps, so yeah there are going to be issues. it is still alpha after all 😉

dominicm23:12:33

yeah, for sure.

dominicm23:12:18

Direct dependency resolved it, opened TDEPS-26 to track

dominicm23:12:17

I've got:

(shadow.server/start! {})
(shadow/watch
{:build-id :hoop/app
                       :target :browser
                       :output-dir "public/hoop/js"
                       :asset-path "/public/hoop/js"
                       :modules {:main {:entries [pro.juxt.hoop.app]}}})
Which is starting a server on 9360, but I can't see the build anywhere, or see any way to access the js, any hints?

dominicm23:12:11

I see a jar-manifest directory

thheller23:12:40

it is in "public/hoop/js"?

thheller23:12:04

can't see the build?

dominicm23:12:17

Not on the filesystem, no. Just used find to check.

dominicm23:12:26

nothing matching "hoop" or ending with ".js"

dominicm23:12:45

(well, nothing not mine matching hoop!)

thheller23:12:08

did it complete?

dominicm23:12:44

user=> (def stop (pro.juxt.krei.core/watch))
shadow-cljs - server running at 
[:hoop/app] Configuring build.
#'user/stop
This is the only output I see, am I doing something wrong maybe?

thheller23:12:42

do you call stop! immediately watch watch?

dominicm23:12:29

krei.core/watch returns a function, which calls (shadow.server/stop!). So, no.

thheller23:12:09

can you try compile* with your config?

thheller23:12:19

dunno why it would stop printing

thheller23:12:25

but no idea what you are doing either

thheller23:12:40

if you are messing with *out* or anything else the output would go elsewhere

dominicm23:12:03

I'm not touching *out*

thheller23:12:12

I'd suggest trying without the complicated stuff first

thheller23:12:15

call start!

thheller23:12:29

see what happens

dominicm23:12:44

user=> (shadow.cljs.devtools.server/start! {})
shadow-cljs - server running at 
:shadow.cljs.devtools.server/started
(shadow.cljs.devtools.api/compile* {:build-id :hoop/app
                       :target :browser
                       :output-dir "public/hoop/js"
                       :asset-path "/public/hoop/js"
                       :modules {:main {:entries '[pro.juxt.hoop.app]}}} {})
[:hoop/app] Compiling ...
AssertionError Assert failed: (cljs-util/is-file-instance? cache-root)  shadow.cljs.devtools.config/make-cache-dir (config.clj:115)
I guess the exception is lost into the background when it happens during a watch.

dominicm23:12:03

I'll have to figure out this cache-root stuff later, I'm probably not specifying something I should be.

thheller23:12:58

hmm that might just be an error since it expects a config file

dominicm23:12:06

Maybe I need to merge in a default config then

thheller23:12:40

no it does that by default

thheller23:12:41

too tired, going to bed. gn8

dominicm23:12:24

I don't see any merge if I explicitly pass an empty map,