Fork me on GitHub

Hi, getting some very weird issue, when trying to run a "Getting Started" guide of Slate.js. It seems like something with closure compiler but I'm completely lost. Anyone saw this before?

index.js:404 Uncaught TypeError: Cannot read property 'prototype' of undefined
    at Object.$jscomp.generator.createGenerator (generator_engine] :879)
    at Object.levels (index.js:755)
    at Object.above (index.js:380)
    at Object.void (index.js:2233)
    at eval (index.js:2092)
    at HTMLUnknownElement.callCallback (react-dom.development.js:189)
    at Object.invokeGuardedCallbackImpl (react-dom.development.js:238)
    at invokeGuardedCallback (react-dom.development.js:293)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:307)
    at executeDispatch (react-dom.development.js:390)
I've been only able to find this issue thus far: which might be or not be similar. The component renders but when I try to edit anything, the error above happens.


Just when I think my mental model of Javascript interop is in sync with reality, the javascript world sends me another cureveball. Especially after being spoiled by npm and shadow-cljs. I have a lame javascript “library that only comes as a javascript file that seems to be intended only to be consumed via a <script> tag, not imported. It’s not an NPM library. If I inject it via the script file it comes in as a nice js function:

WebRTCAdaptor:  λ[mediaConstraints audioConstraint stream]
                jsƒ WebRTCAdaptor(initialValues)
I can then instantiate the main object with a (new js/WebRTCAdapter jsparams) and all is well, until it is :advanced compiled and all the names get munged. I could go thru all the function and property calls and use cljs-oops to ensure they don’t get munged, but it seems like I should be able to figure out how to import /require the js file and shadow-cljs should take care of things (I hope that assumption is correct!) Then I find out I don’t know how to deal with the object that get’s imported/ required. It’s not coming in as a function or an object with a constructor. If I try to :require it like ["./antmedia/webrtc_adaptor.js" :as WebRTCAdaptor] I get the object but, its just an js object:
constructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ toString()
valueOf: ƒ valueOf()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
get __proto__: ƒ __proto__()
set __proto__: ƒ __proto__()
And I can’t do a new (new WebRTCAdaptor jsparams) Uncaught TypeError: module$visx$dashboard$antmedia$webrtc_adaptor is not a constructor or execute it as a function (WebRTCAdaptor jsparams) Uncaught TypeError: module$visx$dashboard$antmedia$webrtc_adaptor is not a function So I come back to the fount of knowledge to humbly ask for guidance. Is there a nice clean way to do this with shadow-cljs or should I just apply some cljs-oops elbow grease to the <script> imported js?


@rberger first of all delete cljs-oops from your mind as an option. NEVER use it. turn on :infer-extern :auto and let the compiler tell you about things it needs externs for. you can just stick a regular CLJS syntax, no need for a library.


would help to see the code. the library seems to have an exported value, otherwise you'd get nothing. looks like that is already an instance of the class it provides.


really up to you if you want to bring the code into your build or leave it in a script


externs inference will probably well you which externs you need. if the JS does too much dynamic stuff it might not survive :advanced because of that. externs aren't enough to fix that, so it just might not be compatible.


@bear-z my guess would be that you are looking at this incorrectly. in general my first guess when something is undefined is that you didn't pass a value that was expected correctly.


Thank you for your time. I'll start with a minimal example to triple check myself. Can I share the code if it doesn't work?


Thank you so much. I just completed the example and it has the same error. Here is the repo with the code: I'm trying to run an example from here: And here is the working javascript code: Thank you again for looking into it. I'm lost and don't know where to dig next.


hmm the problem seems to go away if you set :compiler-options {:output-feature-set :es6}


Is this affects anything else that I should be aware of?


well yeah the code doesn't run in browsers that don't support ES6 (dunno which feature slate uses exactly that causes the error otherwise)


the default is :es5 so the closure compiler will trying to transpile it down


which seems to be causing the issue


but if you don't care about pre 2015 browsers then thats probably fine


Yes. Doesnt' really matter to me. Thank you so much! I wouldn't find this any time soon without your help


Slate is in typescript since recently, probably they target es6 with their compile.


depending on when the library checks what you passed the resulting error might be deep in the code


so first make sure that the arguments you are passing to slate are what they are supposed to be. meaning don't pass CLJS data if it expects JS objects, etc.


I’m curious as to why it works if the webRTCAdapter code is brought in globally with the <script> tag but doesn’t work as an import. If you do have the time to glance at the code it is at


this has no exports so it can't possibly work


Ah, If I were to add something like export WebRTCAdaptor it would work?


you can just add export { WebRTCAdaptor } at the bottom yes


that gives you a :refer (WebRTCAdaptor) in CLJS


Cool, really appreciate your time


quick warning though. the code is not exactly idiomatic JS and closure might have issues with this


you can also add exports.WebRTCAdaptor = WebRTCAdaptor; at the bottom instead of the exports


that turns the code into commonjs, meaning it doesn't go through :advanced and instead uses the same style as node_modules code


so if you have :advanced issues that might be worth trying


sup, does anybody know where's the right place to change :watch-ext ? I'm trying to make shadow reload my static html file changes but can't figure out where to put that config key. Ref: I tried:

      {:app {...
             :devtools {:watch-exts #{"css" "html"}}}}}
... but not luck. Btw, this is not documented afaict.


@emmanueloga that isn't supported. even if you make it watch the html it won't reload it.


that explains it 🙂

Pavel Klavík21:05:48

Hi, I have a problem in advance compilation of NodeJS, probably due to missing extern. I am using Macchiato which has the following line:

(.createServer (node/require "http") http-handler)
When running in advance, I get this:
function mo(a,b,c){var d=null!=b&&(b.h&64||r===b.P)?J.b(dh,b):b,e=E.b(d,oj);b=E.b(d,Si);var f=E.b(d,Zh);if(x(Wk.a(f)))return null;try{var g=e.j?e.j();hf.c(c,sd,a);var k=g}catch(l){throw b=l,Error([["could not start [",C.a(a),"] due to"].join("")," ",C.a(b)].join(""));}c=k;d=null!=d&&(d.h&64||r===d.P)?J.b(dh,d):d;d=E.b(d,wm);gf(d,c);hf.H(ko,W,a,new v(null,1,[Si,b],null));return hf.H(jo,xf,new X(null,2,5,Y,[a,Zh],null),new mh(null,new v(null,1,[Wk,null],null),null))}

Error: could not start [#'orgpad.screenshot.core/server] due to TypeError: (intermediate value)(intermediate value)(intermediate value).rd is not a function
    at mo (C:\Shared\orgpad\screenshot\screenshot.js:443:204)
    at (C:\Shared\orgpad\screenshot\screenshot.js:449:21)
    at so (C:\Shared\orgpad\screenshot\screenshot.js:447:276)
    at Function.<anonymous> (C:\Shared\orgpad\screenshot\screenshot.js:556:154)
    at Function.J.b (C:\Shared\orgpad\screenshot\screenshot.js:169:112)
    at C:\Shared\orgpad\screenshot\screenshot.js:556:119
    at Object.<anonymous> (C:\Shared\orgpad\screenshot\screenshot.js:557:3)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
When switching to :simple compilation, everything works fine.


Hi, I'm trying to compile a project (that was working on 2.8.109) with the current version 2.9.10. Something strange is happening: when I try to watch my node-library project, it's printing the following on terminal:

[:dev] Configuring build.
[:dev] Compiling ...
[:dev] Build completed. (213 files, 212 compiled, 0 warnings, 33.38s)
[:dev] Compiling ...
[:dev] Build completed. (213 files, 0 compiled, 0 warnings, 0.07s)
[:dev] Compiling ...
[:dev] Build completed. (213 files, 58 compiled, 0 warnings, 1.21s)
[:dev] Compiling ...
[:dev] Build completed. (213 files, 92 compiled, 0 warnings, 7.22s)
[:dev] Compiling ...
[:dev] Build failure:
The required namespace "shadow.umd-helper" is not available.


Why are you using advanced compilation?

Pavel Klavík21:05:29

Not sure, it was the default. The file is little bit smaller, might be faster. Not really that important in the end, since the server is really tiny.


I’m surprised it’s the default. What build target are you using?


What does you shadow-cljs.edn file look like?


I believe all targets on shadow-cljs defaults to :advanced...

Pavel Klavík21:05:11

The entire build config looks like this:

:screenshot {:target           :node-script
                             :main             orgpad.screenshot.core/main
                             :output-to        "screenshot/screenshot.js"
                             :devtools         {:autoload true}
                             :compiler-options {:optimizations :simple}}


Delete those compiler options. Shadow uses sensible defaults


Node doesn’t I don’t believe


No benefit to advanced


Oh does it?

Pavel Klavík21:05:26

it was broken without them, so I added them to make it work for now


everything defaults to :advanced


it is broken because of machiato doing nonsense


(.createServer (node/require "http") http-handler) this I mean ...

Pavel Klavík13:05:16

how should this be changed to make it work with Shadow-cljs?


it works just fine. it just isn't recognized by externs inference


should be (:require ["http" :as http]) in the ns and then (http/createServer ...) but that might have issue with regular cljs

Pavel Klavík20:05:17

so how could this be solved if one wants to be compatible with regular cljs?


add externs inference hints in the code


and maybe others .. whatever else fails


but yeah if you are fine with :simple then use it


@thheller any tips on debugging The required namespace "shadow.umd-helper" is not available. happening?


i apologize. i thought i remember reading that a few targets did not use advanced. the node ones in particular. i was wrong


not really. can you narrow it down when it happens?


like editing a specific file or so? it is a generated namespace so not sure how it could be missing


When I try to compile Chlorine source. Just compile, nothing fancy happening


seems to work a couple of times and then doesn't


Like, I just watch the file, it says 3 times that build is complete, but then tries to compile again


so something must happen that is causing it to stop working


you mean it compiles 3 times on its own without you doing anything?


and you are sure that NOTHING is touching any files or so?


wouldn't be the first time that some editor setup just does stuff. like running a linter, formatter or whatever


you can set :log {:level :debug} in shadow-cljs.edn that will give you a little more log output


Okay, I just closed all editors, everything that can touch files, removed old compilation files, and added that option to shadow, the error still happens... Still says "Build completed" twice, then fails 😞


Wait... there's something strange indeed on my config


Nevermind - the output-dir was included on source-files.


If I remove it, it works


Thanks a lot! With :level :debug I saw:

[2020-05-30 18:44:37.353 - FINE] :shadow.cljs.devtools.server.reload-classpath/classpath-js-update - {:dir #object[ 0xbbe1be95 "/home/mauricio/.atom/packages/chlorine/lib"], :name "js/cljs-runtime/sci.impl.max_or_throw.js", :ext "js", :file #object[ 0xa45ec655 "/home/mauricio/.atom/packages/chlorine/lib/js/cljs-runtime/sci.impl.max_or_throw.js"], :event :mod}
And that gave me clues on what's wrong 👍


hmm weird. those are supposed to be filtered. it shouldn't be watching cljs-runtime folders.


but yeah output dirs on the classpath is not a great idea


fighting with nrepl again ... one day I'll make it my mission to kill nrepl. so extremely annoying to work with for CLJS ...


Do shadow-cljs have a ClojureScript nREPL? Or it works the same as piggieback, for example?


it has its own nrepl middleware. piggieback exists but isn't used. only there because other middleware expects it.


Is there any documentation that tooling authors can follow? Or do you not recommend using it?


no extra docs, you just use nrepl as normal

👍 4

I mean you can read piggieback docs or whatever