Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precaching modules throws error to console #1433

Closed
bennypowers opened this issue Apr 15, 2018 · 3 comments
Closed

Precaching modules throws error to console #1433

bennypowers opened this issue Apr 15, 2018 · 3 comments

Comments

@bennypowers
Copy link

bennypowers commented Apr 15, 2018

Thank you for this excellent and highly useful software.

Library Affected:
workbox-sw

Browser & Platform:
Chrome 68

Issue or Feature Request Description:
When precaching modules (by which I mean standard or es modules) with workbox, I see errors in browser console such as

Uncaught (in promise) SyntaxError: Unexpected token {
    at Object.<anonymous> (workbox-core.dev.js:941)
    at Generator.next (<anonymous>)
    at step (workbox-core.dev.js:14)
    at workbox-core.dev.js:25
(anonymous) @ workbox-core.dev.js:941
step @ workbox-core.dev.js:14
(anonymous) @ workbox-core.dev.js:25

The error in question was throw from https://github.com/bennypowers/mws-restaurant-stage-1/blob/a46986f1b896847e7374c02839a5abc6a73278c5/js/lib.js#L1

Repro by installing that repo and running.

For reference, the workbox-config.js at that commit is

module.exports = {
  "globDirectory": ".",
  "globIgnores": [
    "js/idb-keyval.js",
    "**/service-worker.js",
    "node_modules/**/node_modules/**/*",
    "node_modules/**/bower_components/**/*"
  ],
  "globPatterns": [
    "js/*",
    "css/*",
    "index.html",
    "manifest.json"
  ],
  swSrc: 'service-worker.src.js',
  swDest: 'service-worker.js',
};

and the service-worker.src.js is

importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js');

/* global workbox */

workbox.skipWaiting();
workbox.clientsClaim();

workbox.routing.registerNavigationRoute('/index.html');

workbox.routing.registerRoute(
  /.*(?:googleapis|gstatic)\.com.*$/,
  workbox.strategies.staleWhileRevalidate({cacheName: 'googleapi-cache'}),
);

workbox.routing.registerRoute(
  /.*\.(?:js|html|css)/,
  workbox.strategies.cacheFirst({cacheName: workbox.core.cacheNames.precache})
);

workbox.routing.registerRoute(
  /.*\.(?:png|jpe?g|svg|gif)/,
  workbox.strategies.cacheFirst({cacheName: 'img-cache'})
);

workbox.routing.registerRoute(
  /\/api\/.*/,
  workbox.strategies.cacheFirst({cacheName: 'data-cache'})
);

workbox.precaching.precacheAndRoute([]);
@jamrelian
Copy link

I'm getting the same type of errors when using ES6 Modules with Workbox precaching:

image

This is "for real", as the service worker doesn't get registered:

image

and the built-in Lighthouse audit tool reports that "user will not be prompted to install the Web App":

image

This is on Google Chrome 65.0.3325.181 (Official Build) (64-bit), running on Windows 10 Home 10.0.16299 Build 16299.

This is the workbox-config.js:

module.exports = {
    "globDirectory": "./docs",
    "globPatterns": [
        "*.html",
        "scripts/*.js",
        "styles/*.css"
    ],
    "swDest": "./docs/sw.js"
};

The hello.js file that throws the error is native JavaScript module with a single export default function. On refresh, I get the error in app.js, which is a script module that imports the function from hello.js.

What's even stranger is that, on Chrome on Android 7.0, on a cached PWA that uses Workbox, the Add to Home screen which used to install the PWA, after refresh now it only offers to add it as a simple shortcut.

@jeffposnick
Copy link
Contributor

I've opened up a fresh issue, https://bugs.chromium.org/p/chromium/issues/detail?id=833501, to track this from a Chrome perspective. I'm assuming that, like the last time this cropped up, it's something outside of Workbox's control, so I'm going to close this issue.

Please star, and follow-up on that new Chromium Tracker issue.

@jamrelian
Copy link

jamrelian commented Apr 18, 2018

@jeffposnick Issue 833501 has been merged into issue 832202, so the new URL is
https://bugs.chromium.org/p/chromium/issues/detail?id=832202

Indeed, it's a Chrome issue, can be reproduced using standard Cache API instead of Workbox:
https://github.com/hwalab-developer/swesmit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants