Search code examples
javascriptreactjsnext.jsprogressive-web-appsnext-pwa

Failed to register a ServiceWorker (Next.js)


i have created a sample next project i use this command : npx create-next-app i install next-pwa after that i configure next.config,create manifest.json and _document.js in project directory

this is my next.config.js :

const withPWA = require("next-pwa");

module.exports = withPWA({
reactStrictMode:true,
pwa: {
dest: "public",
register: true,
skipWaiting: true,
disable: process.env.NODE_ENV === 'development'
}

});

my _document.js :

import Document, { Html, Head, Main, NextScript } from "next/document";

class MyDocument extends Document {
render() {
    return (
        <Html>
            <Head>
                <link rel="manifest" href="/manifest.json" />
                <link rel="apple-touch-icon" href="/icon.png"></link>
                <meta name="theme-color" content="#fff" />
            </Head>
            <body>
            <Main />
            <NextScript />
            </body>
        </Html>
    );
}
}

export default MyDocument;

after run : npm run build and npm start i saw this error : enter image description here

Anyone have a solution?


Solution

  • Looks like a bug. Please, downgrade next-pwa version to 5.5.4 and it should work.