unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.45k stars 471 forks source link

Nitro `service-worker` preset not working with Nuxt 3 #1105

Open PatrickMcGrath29 opened 1 year ago

PatrickMcGrath29 commented 1 year ago

Environment


Reproduction

  1. Set the nitro preset to service-worker
  2. Run yarn build followed by yarn preview
  3. Visit the exposed endpoint, and observe that Initializing nitro service worker... is displayed on a blank screen.

Describe the bug

I'm trying to run my Nuxt 3 app with ssr: false using the Nitro service-worker preset, however whenever I deploy to Netlify or look at the local assets generated from yarn build, the only thing displayed on the screen is Initializing nitro service worker....

Additional context

I want to support offline queries to Nuxt content, and it seems like the only way to do that with Nuxt 3 is using the service-worker preset. Because I'm unable to get this working I'm unable to finish my migration from Nuxt 2 to Nuxt 3.

Logs

Browser console logs:

index.js:33 Uncaught TypeError: Cannot read properties of undefined (reading 'split')
    at index.js:33:42
    at client.manifest.mjs:838:1
    at sw.js:1:6
(anonymous) @ index.js:33
(anonymous) @ client.manifest.mjs:838
(anonymous) @ sw.js:1

(index):17 Uncaught (in promise) TypeError: Failed to register a ServiceWorker for scope ('http://localhost:3000/') with script ('http://localhost:3000/sw.js'): ServiceWorker script evaluation failed

Webserver logs (yarn preview)

 HTTP  4/1/2023 12:31:45 PM ::1 GET /Users/.../.../.../node_modules/readdirp/index.js
 HTTP  4/1/2023 12:31:45 PM ::1 GET /Users/.../.../.../.nuxt/dist/server/client.manifest.mjs
 HTTP  4/1/2023 12:31:45 PM ::1 Returned 404 in 3 ms
 HTTP  4/1/2023 12:31:45 PM ::1 Returned 404 in 2 ms
danielroe commented 1 year ago

Would you provide a reproduction? 🙏

gbyesiltas commented 1 year ago

I experience the exact same issue :(