vite-plugin-pwa: WorkboxError non-precached-url index.html

Hi, thank you for this plugin.

I’m getting the error below when running the app with vite preview and in production. The app source code is available at https://github.com/jonian/awmonitor and the production link is https://awmonitor.netlify.app.

WorkboxError.js:28 Uncaught (in promise) non-precached-url: non-precached-url :: [{"url":"index.html"}]
    at x.createHandlerBoundToURL (http://localhost:5000/workbox-a59a8da5.js:1:12967)
    at Object.createHandlerBoundToURL (http://localhost:5000/workbox-a59a8da5.js:1:14597)
    at http://localhost:5000/sw.js:1:10085
    at http://localhost:5000/sw.js:1:695
s @ WorkboxError.js:28
createHandlerBoundToURL @ PrecacheController.js:276
(anonymous) @ createHandlerBoundToURL.js:29
(anonymous) @ sw.js:486
(anonymous) @ sw.js:1

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I use this config now - not sure if it’s fully correct but seems to be working:

{
  strategies: 'generateSW',
  workbox: {
    // Only precache these files - html should be excluded
    globPatterns: ['**/*.{js,css}'],

    // Don't fallback on document based (e.g. `/some-page`) requests
    // Even though this says `null` by default, I had to set this specifically to `null` to make it work
    navigateFallback: null,
}

This seems to remove the generated config containing the index.html, which is then just handled by the server.

I use this config now - not sure if it’s fully correct but seems to be working:

{
  strategies: 'generateSW',
  workbox: {
    // Only precache these files - html should be excluded
    globPatterns: ['**/*.{js,css}'],

    // Don't fallback on document based (e.g. `/some-page`) requests
    // Even though this says `null` by default, I had to set this specifically to `null` to make it work
    navigateFallback: null,
}

This seems to remove the generated config containing the index.html, which is then just handled by the server.

Thanks. I was having the same issue here, this config. helped out.

Well, the problem is on your workbox.globPatterns entry: you need to include all, it is exclusive, that is, if you include this entry, you MUST add all your patterns, not only font assets: in your case, you are not including js and css assets and index.html page.

Since you are using vite, all entries under assets directory will be included, you don’t need to add them again.

Just remove the workbox entry from your configuration:

imagen

imagen

You also need to add all red entries shown bellow to make it work offline, it is working, but some images missing:

imagen

I made a quick PR to update the type docs: https://github.com/GoogleChrome/workbox/pull/3106

Sorry to pickup an old thread here, however this is causing some confusion for me.

I’m using Vite to SSR a page, however the index.html file gets added to the client bundle even though it’s not served by users. My server returns the HTML, however with the index.html file being cached, it’s returning the version of my html which is missing things (e.g. I replace <!-- app-head --> on the server to add metadata). The SW kicks in and serves the cached file instead of the server.

If I add the html file to the ignore glob, I get the non-precached-url: non-precached-url error described here.

@userquin I have got a similar problem, how can i exclude the html file.

Sorry to pickup an old thread here, however this is causing some confusion for me.

I’m using Vite to SSR a page, however the index.html file gets added to the client bundle even though it’s not served by users. My server returns the HTML, however with the index.html file being cached, it’s returning the version of my html which is missing things (e.g. I replace <!-- app-head --> on the server to add metadata). The SW kicks in and serves the cached file instead of the server.

If I add the html file to the ignore glob, I get the non-precached-url: non-precached-url error described here.