Fork me on GitHub

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.

😱 4

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


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?


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


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


hopefully that helps


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")?


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


well its spread across multitple files



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


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


> Node.js client library for using Google APIs.


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

facepalm 4

yeah that definitely isn't made for the browser. looks like you are supposed to use this for the browser

❤️ 4
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

Drew Verlee17: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?


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


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


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


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


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

Drew Verlee17:11:05

Each ns becomes a module right?


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


with :depends-on setting up the relationships

Drew Verlee17: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?

Drew Verlee17: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.


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


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


no fancy visuals though

Drew Verlee18:11:30

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


I don't know?


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?


what did you try?


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


which config did you add?


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


see the :http-port so you open


and that doesn't run the tests?


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


the page you should see is the test report?


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


the result should look something like this


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


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


conflicting index.htmls