vite-pwa/vite-plugin-pwa

Uncaught (in promise) non-precached-url: non-precached-url :: [{"url":"/"}]

meliceanu opened this issue · 19 comments

Is there a way to get rid of this error?

screenshot

I tried to use the config https://vite-pwa-org.netlify.app/guide/service-worker-precache.html but nothing seems to work, i use Nuxt 3.12.3 and @vite-pwa/nuxt 0.9.1

Thank you

You need to prerender / route, workbox requires the html to be there to allow work offline (precaching): don't use vite plugin pwa, use the nuxt integration

how can i do that? do i need to add a index.html file in the root even tho i don't need it?

somehow the error still appears, only in production. it's hosted on netlify

open devtools and remove sw, then page refresh

it just automatically reregisters the sw, with the same error

can you check if working in your local with build/generate? (follow nuxt instructions once build/generate command finish)

EDIT: remove the edge preset

ok i removed the edge preset and kept the prerendering of the / page in the route. but the error is still there

only in chrome i get that error, in safari i get this

Screenshot 2024-07-18 at 14 56 06

check dist or output folder, you should have the html file there, some questions:

  • ssr enabled?
  • how do you build the app (build or generate command)?

The index.html should be in the sw.js file, check the sw.js file at the end, there should be something like:

{ url: "/", revision: "xxxxxx" } 

ssr is enabled i build the app using pnpm run build. in my sw.js file i dont see any url: "/"

this is what i think is the / page:

{ url: '_payload.json', revision: 'fc92125330b4f4ac06b2d1f6acfaff6d' },

all my other pages are:

{ url: 'example-route/_payload.json', revision: 'fc92125330b4f4ac06b2d1f6acfaff6d' },

this is the end of the file

Screenshot 2024-07-18 at 15 10 03

did you add nitro.prerender.routes with / in the array?

i did, the error keeps appearing

is the prerendering a must? it seems it's not working

why are you removing html files from glob patterns? remove that entry https://vite-pwa-org.netlify.app/guide/static-assets.html#globpatterns

you're removing sw precaching, your app will not work when offline

remove workbox entry, check if the html pages being generated in the output folder

So i had to remove nay reference to the manifest or manifest.webmanifest, deleted the file as well. The pwa options handel the manifest. Note the scope and the theme-color options.
pwa

I had to change the app.vue configuration cause i use the assets generator:
app

Corrected Nitro configuration, you don't really need the preset, it's just personal choice. Need to prerender the '/' route
nitro

If you then have the bad-precaching-response, with a 404 status, you have to exclude that file/url from the pwa build:
second-error

All of this thanks to @userquin