shadowwalker / next-pwa

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

'disable' option not disabling pwa feature in development mode. #371

Closed david-buck closed 2 years ago

david-buck commented 2 years ago

Summary

My next.config.mjs file has next-pwa configured like so:

export default withPWA({
  pwa: {
    dest: "public",
    register: false,
    skipWaiting: false,
    dynamicStartUrl: false,
    runtimeCaching,
    disable: process.env.NODE_ENV === "development",
  }, ...

The disable option seems to be ignored, even if set to disable: true which leads to all the quirks that come with running next-pwa in development mode.

Versions

How To Reproduce

Steps to reproduce the behavior:

  1. add disable: true option to next.config.js
  2. yarn dev
  3. see warnings in console:
warn  - GenerateSW has been called multiple times, perhaps due to running webpack in --watch mode. The precache manifest generated after the first call may be inaccurate! Please see https://github.com/GoogleChrome/workbox/issues/1790 for more information.
phil-madpaws commented 2 years ago

Using this as a workaround for now:

module.exports = prod ? withPWA(nextConfig) : nextConfig;

piro0919 commented 2 years ago

I think it works fine with v5.5.4. I'm sorry, but I haven't investigated the cause yet. I think maybe the flag handling is reversed.

ymchun commented 2 years ago

seems related to this line: https://github.com/shadowwalker/next-pwa/blob/9d28c3be6aa6cc082a2ca87ba61117fff57ded8f/index.js#L338 .pwa config is deleted too early so that webpack function can't read any user config.

https://github.com/shadowwalker/next-pwa/blob/9d28c3be6aa6cc082a2ca87ba61117fff57ded8f/index.js#L56 the value of pwa variable is {}

faisalamin001 commented 1 year ago

Using this as a workaround for now:

module.exports = prod ? withPWA(nextConfig) : nextConfig;

it worked for me as well, thanks! @phil-madpaws