Fork me on GitHub
#shadow-cljs
<
2019-11-22
>
thheller12:11:37

anyone using :npm-module please let me know what you use it for so I can better decide what to do about it. currently a good chunk of the open shadow-cljs issues are about problems with :npm-module and it is becoming harder to maintain with each new closure compiler release. https://github.com/thheller/shadow-cljs/issues/605

😱 1
aisamu03:11:01

Oh, my! We rely heavily on it, converting an existing JS webpack project into a CLJS one, piece by piece!

thheller09:11:57

yes but do you actually require separate namespaces? I mean from the JS code do you actually var x = require("wherever/one.ns.from-your-app") for more than 1 namespace?

nickmbailey14:11:44

we have a utility library that among other things we use to construct schema definitions for our domain and then share those definitions across all our codebases. this includes our frontend which is written in plain javascript. we bundle up this utility library using shadow-cljs with :npm-module and then we include it in our ui app the same as any other dependency

nickmbailey14:11:09

mostly the schema definitions are responsible for taking a big json blob off the wire and coercing it into something useable in clojure/js as well as proving a useful error if it doesn't conform to the model we expect

nickmbailey14:11:46

hopefully that helps

thheller14:11:18

but you are not using any of the :npm-module specific things? like require("./some-folder/one.simple.namespace") and require("./some-folder/another.namespace")?

thheller14:11:40

its just one primary export I presume like import { checkSchema } from "somewhere"?

nickmbailey14:11:07

well its spread across multitple files

nickmbailey14:11:57

so

import * as userSchema from 'utilityboss/public/utilityboss.schema.users';

nickmbailey14:11:08

and another namespace for other collections of related things

Lucas Barbosa14:11:49

I'm trying to use Google's OAuth api. I installed the npm library using npm install googleapis and I am trying to require it in my .cljs file. This is my ns form:

(ns app.core
  (:require [re-frame.core :as rf]
            [reagent.core :as reagent]
            ["googleapis" :refer [google]]))
The browser outputs the following error:

Lucas Barbosa14:11:49

Did I forget to do something? I tried scraping the Internet for more clues but I could not find anything

thheller17:11:34

> Node.js client library for using Google APIs.

thheller17:11:59

@lvbarbosa are you sure those are supposed to work in the browser? quick glance at the docs suggests they are meant for node?

facepalm 1
thheller17:11:30

yeah that definitely isn't made for the browser. looks like you are supposed to use this for the browser https://developers.google.com/docs/api/quickstart/js

❤️ 1
Lucas Barbosa20:11:18

Sorry for the late response! facepalm my bad, I'll take a look on the one you referenced! Thanks a lot

drewverlee17:11:47

when building my app via shadow cljs watch app i get the following logs:

[:app] Build failure:
Module Entry "some.namespace.module.main was moved out of module ":module".
It was moved to ":main" and used by #{:module :main}.
I'm not sure what the logs are telling me. I understand there is a build failure. But is it saying the module move (i am trying to do code splitting) is the issue?

thheller17:11:34

for code splitting to work you can't have a direct require on the namespaces

thheller17:11:59

so likely something in your :main directly required something from :module

lilactown17:11:12

yeah, what it's saying is: there's a dependency inside your :main module on the :module entry point

lilactown17:11:40

if :main gets loaded without :module then it will break the code

thheller17:11:27

the error just tells you that you did code splitting wrong as your ns require setup caused all code to me moved to one module and not where you intended things to go

drewverlee17:11:05

Each ns becomes a module right?

thheller17:11:52

each entry namespace plus all of its dependencies, becomes one module/chunk

thheller17:11:25

with :depends-on setting up the relationships

drewverlee17:11:27

Thanks. So if my goal is to split the code up, ill have to make sure everything is lazyly imported. Is there a way to know the dependency tree so that i can systematically prune out deps?

drewverlee17:11:43

e.g main -> foo -> bar main -> bar I can see main points to bar directly in the main ns, but how would i track down main -> foo -> bar. I assume this is the problem im having.

thheller17:11:21

when you open the shadow-cljs ui and run the build through that (default at http://localhost:9630) there is a basic interface to show dependencies

thheller17:11:37

select the namespace and it'll show you everything that was responsible for including it

thheller17:11:46

no fancy visuals though

drewverlee18:11:30

thanks again 🙂 Assuming everything builds correctly. What would the error: Unknown module: <module name> imply?

thheller18:11:11

I don't know?

padraic21:11:20

Hi, I'm reading through the docs and am trying to do some in browser testing. The docs mention that it contains a built in test runner but I cannot seem to trigger it?

thheller21:11:29

what did you try?

padraic21:11:31

I added the configuration in the docs and got the server up and running. I don't know how to get the tests to run in-browser is the thing

thheller22:11:26

which config did you add?

padraic22:11:11

:builds {:test     {:target    :browser-test
                     :test-dir  "target/test"
                     :ns-regexp "-test$"
                     :devtools  {:http-port          8021
                                 :http-root          "target/test"}}

thheller22:11:42

see the :http-port so you open

thheller22:11:32

and that doesn't run the tests?

padraic22:11:37

I got that far but there was no console output or any evidence of something happening

thheller22:11:19

the page you should see is the test report?

padraic22:11:10

Let me validate a thing or two and I'll get back

thheller22:11:51

the result should look something like this https://github.com/bhauman/cljs-test-display

padraic22:11:42

aah that's nice. I hope I'll get it going

padraic22:11:33

I got it, had set the test-dir to be the same as the browser target

padraic22:11:43

conflicting index.htmls