shadowwalker / next-pwa

Zero config PWA plugin for Next.js, with workbox 🧰
MIT License
3.86k stars 323 forks source link

service worker script returns 404 #378

Closed mismosmi closed 2 years ago

mismosmi commented 2 years ago

Summary

Hi, it seems that something has been broken in the latest release (5.5.5). The necessary files (sw.js etc.) do not get generated in /public anymore.

Versions

How To Reproduce

Steps to reproduce the behavior:

  1. Go to this codesandbox
  2. wait for it to start
  3. see the error message

Link to minimal reproduce setup repository if any. https://codesandbox.io/s/bitter-breeze-xcpdqh

Expected Behaviors

sw.js and workbox-[hash].js should be generated in public folder

Screenshots

Screenshot 2022-08-01 at 15 10 37

Additional Context

Might not get noticed until deployed if files are still in the filesystem from before the upgrade.

Best, Michel

mgoodfellow commented 2 years ago

We are also suffering this issue - seems to be a breakage in 5.5.5

It seems to be ignoring settings passed in now?

v5.5.5

> [PWA] Compile client (static)
> [PWA] Auto register service worker with: XXXX\node_modules\next-pwa\register.js
> [PWA] Service worker: XXX\src\site\.next\sw.js
> [PWA]   url: /sw.js
> [PWA]   scope: /

v5.5.4:

> [PWA] Compile client (static)
> [PWA] Auto register service worker is disabled, please call following code in componentDidMount callback or useEffect hook
> [PWA]   window.workbox.register()
> [PWA] Service worker: XXXX\src\site\public\sw.js
> [PWA]   url: /sw.js
> [PWA]   scope: /

Config:

    pwa: {
        dest: 'public',
        register: false,
        skipWaiting: false,
        buildExcludes: [/.map$/],
    },
adrianstanek commented 2 years ago

Having the same issue after updating to 5.5.5. After rollback to previous version it was fine again. The sw.js and workbox file weren't generated into /public (dest) anymore.

I noticed that bug after the PWA wasn't updating itself on android chrome anymore since service worker was 404.

should be in /public instead of /.next:

> [PWA] Service worker: /Users/workspace/mono/app-client/.next/sw.js
> [PWA]   url: /sw.js
ashish1497 commented 2 years ago

Also, if I write SW in options to look for different serviceWorker.js files in the public folder, it's not looking for the same.

Lukasdotcom commented 2 years ago

372 may resolve this problem.

shestakov-vladyslav commented 2 years ago

I am experiencing the same issue

tusqasi commented 2 years ago

How do i solve this for now?

Lukasdotcom commented 2 years ago

The best fix is downgrading to version 5.5.4

tusqasi commented 2 years ago

ok, thanks

felixmosh commented 2 years ago

This PR is related to the issue, https://github.com/shadowwalker/next-pwa/pull/368

f4z3k4s commented 2 years ago

@Lukasdotcom any tip is appreciated.

The best fix is downgrading to version 5.5.4

What is the compatible next version and pwa config in next.config.js that works with next-pwa@5.5.4? Locally I am able to run it fine (Lighthouse checkmark, PWA is correctly set) with next@12.1.6 and this config:

  pwa: {
    dest: 'public',
    // register: true,
    // skipWaiting: true,
    runtimeCaching,
    buildExcludes: [/middleware-manifest.json$/],
  },

However, when deployed to Vercel on production, Lighthouse shows there's no service worker: Does not register a service worker that controls page and start_url

I've tried messing up with the config based on several issues of this repo, none of them seems to work in production.