next-pwa is not working and there is no error in production

1.3k Views Asked by At

The repo is open source

// next.config.js
const withPWA = require("next-pwa");

module.exports = withPWA({
  pwa: {
    dest: "public",
    sw: '/sw.js'
  },
});

_document.js

_app.js

Live

https://time-stamp.vercel.app

I have checked weather the PWA is working on the above URL or not using

function isPwa() {
    return ["fullscreen", "standalone", "minimal-ui"].some(
        (displayMode) => window.matchMedia('(display-mode: ' + displayMode + ')').matches
    );
}
isPwa() // false
// https://stackoverflow.com/questions/41742390/javascript-to-check-if-pwa-or-mobile-web
2

There are 2 best solutions below

1
On

You may want to use the next-pwa package like this :

const withPWA = require("next-pwa");
const runtimeCaching = require("next-pwa/cache");

module.exports = withPWA({
  pwa: {
    dest: "public",
    runtimeCaching,
    disable: process.env.NODE_ENV === "development",
  }
});

1
On

updating the next-pwa and following the steps in https://stackoverflow.com/questions/73585089/build-error-when-compiling-next-js-app-using-next-pwa worked for me