Fork me on GitHub
#shadow-cljs
<
2019-04-04
>
thheller09:04:13

@markx I actually don't like it much. the interceptor design is better in general but some design choices are weird

orestis10:04:55

I liked the fact that Pedestal was ready to go for “production” with some logging etc (and also I liked the interceptor concept). No regrets so far for using it, as you can reuse all the ring middleware out there.

Michael Porter14:04:44

Hi, I'm fairly new shadow-cljs, but very impressed so far. I'm having an issue though where I get a Uncaught ReferenceError: regeneratorRuntime is not defined message in the browser console. I'm using the npm workbox-precaching package (in a service worker) and the error is occurring in one of the source files this uses (`node_modules/workbox-core/_private/quota.mjs`). It seems that this file (that uses async/`await`) is getting transpiled to ES5 and the transpiled version is expecting a global regeneratorRuntime to be defined:

var executeQuotaErrorCallbacks = function () {
  var _ref = global.shadow.js.babel.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
    var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, callback;

    return regeneratorRuntime.wrap(function _callee$(_context) {
Has anyone come across this before?

Michael Porter15:04:43

As a workaround, I've found I can get this to work by prepending the JS file that defines regeneratorRuntime (https://raw.githubusercontent.com/facebook/regenerator/master/packages/regenerator-runtime/runtime.js) to my worker.js file that shadow-cljs generates. Is there a mechanism in shadow-cljs that will allow me to prepend some JS to a module?

thheller17:04:45

@mike469 what do you require? by default it should be using the node_modules/workbox-precaching/dist/workbox-precaching.prod.js. which doesn't work either but for different reasons?

Michael Porter17:04:16

I'm doing (:require ["workbox-precaching/precacheAndRoute.mjs" :refer (precacheAndRoute)]) currently which is causing the regeneratorRuntime error. I don't seem to have a dist dir in node_modules/workbox-precaching

thheller17:04:38

hmm which version do you use? I just installed [email protected]

thheller17:04:15

but yeah including the .mjs directly will skip the prod file

Michael Porter17:04:57

my current versions are: ` "workbox-precaching": "^4.1.1", "workbox-routing": "^4.2.0", "workbox-strategies": "^4.2.0"

Michael Porter17:04:49

not sure why there would be no dist, I just npm install'd them

thheller17:04:46

so the problem is that the babel parts are not meant to rewrite the async/await at all

thheller17:04:50

but for some reasons they do

thheller17:04:55

I'm only using babel to rewrite import -> require since it works differently than what the closure compiler does

thheller17:04:10

non standard behavior that is the cause of many headaches ...

thheller17:04:19

hmm yeah the code is pushing my simple babel interop a bit too far

Michael Porter17:04:18

hmm I see, so have you managed to get workbox-precaching working with shadow-cljs previously? Perhaps I just need to figure out why I'm missing the 'dist' versions?

thheller17:04:37

no I haven't worked with that through shadow-cljs

thheller17:04:48

I tried using the workbox cli directly and use that output

thheller17:04:27

the dist files don't work either so don't worry about it

Michael Porter17:04:13

ah ok, so is it babel that inserts the regenerator references?

thheller17:04:49

the problem is polyfilling ...

thheller17:04:57

that is currently not configurable for node_modules files

thheller17:04:18

it shouldn't touch this at all and just leave async/await as they are as server workers support that

thheller17:04:54

so usually you'd set :compiler-options {:output-feature-set :es7} (or whatever async/await was)

thheller17:04:59

and the compiler would leave it alone

Michael Porter17:04:09

yes I did try that but found it had no effect

thheller17:04:15

but that doesn't yet work for node_modules since it goes through some naive babel processing first

thheller17:04:02

I had to go through babel since babel added some non-standard ESM->CJS interop that lots of npm libs rely on

thheller17:04:15

the google closure compiler only allows the strict interop and breaks many packages

thheller18:04:04

I can try something maybe that helps

Michael Porter18:04:08

FYI adding the regenerator-runtime/runtime.js verbatim to the start of my generated worker js bundle does fix it for me in this instance

thheller18:04:32

yes but the point is that all that is not required

Michael Porter18:04:39

(I'm only testing in dev mode currently)

thheller18:04:47

service-workers support async/await so they should not be rewritten to add that huge regenerator crap

Michael Porter18:04:16

Right yes understood. I have to go out now but thanks for your help and drop me a message if you want me to try anything out