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

Workbox fails to initialize with incorrect cache key #2153

Closed
wallzero opened this issue Jul 30, 2019 · 1 comment
Closed

Workbox fails to initialize with incorrect cache key #2153

wallzero opened this issue Jul 30, 2019 · 1 comment
Assignees
Milestone

Comments

@wallzero
Copy link

Library Affected:
[email protected], GenerateSW

Browser & Platform:
n/a

Issue or Feature Request Description:

Currently I receive the following browser error with my SPA setup:

Uncaught incorrect-type: The parameter 'cachedAssetUrl' passed into 'workbox-routing.registerNavigationRoute()' must be of type string.
    at Object.isType (http://localhost:8080/bundle/workbox/workbox-v4.3.1/workbox-core.dev.js:457:13)
    at Object.registerNavigationRoute (http://localhost:8080/bundle/workbox/workbox-v4.3.1/workbox-routing.dev.js:814:25)
    at http://localhost:8080/workbox.js:39:17

This is my current setup in webpack:

new GenerateSW({
        cacheId: 'any',
        directoryIndex: 'index.html',
        exclude: [/\.map($|\?)/, /\.gz$/],
        importsDirectory: 'workbox',
        importWorkboxFrom: 'local',
        navigateFallback: '/index.html',
        navigateFallbackBlacklist: [/^\/bundle/],
        precacheManifestFilename: 'workbox.manifest.js?[manifestHash]',
        swDest: path.join('..', 'workbox.js')
})

The problem is in the generated workbox.js:

self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.precacheAndRoute(self.__precacheManifest, {
  "directoryIndex": "/index.html"
});

workbox.routing.registerNavigationRoute(workbox.precaching.getCacheKeyForURL("/index.html"), {
  blacklist: [/^\/bundle/],
});

.getCacheKeyForURL() is returning undefined. The precache key shouldn't have the the leading forward slash. Everything works if I remove it:

workbox.precaching.getCacheKeyForURL("index.html")

In searching I noticed the following PR #1874 which uses navigateFallback for the cache key. Perhaps this should instead be using directoryIndex?

I also see that registerNavigationRoute() has been deprecated, so perhaps this issue is late and can be ignored. I will test the next @5.0-alpha when #2143 is merged.

@jeffposnick jeffposnick self-assigned this Jul 30, 2019
@jeffposnick jeffposnick added this to the v5 milestone Jul 30, 2019
@wallzero
Copy link
Author

I've managed to fix the issue by prefixing the applications <base> href to navigateFallback. Now .getCacheKeyForURL() finds a match.

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

No branches or pull requests

2 participants