next-pwa icon indicating copy to clipboard operation
next-pwa copied to clipboard

Service Worker not generated in public folder

Open mrmonat opened this issue 1 year ago • 16 comments

Summary

Starting with version 5.5.5 when running npm run build no sw.js and no workbox-*.js file is generated in the public folder. When downgrading to 5.5.4 everything works as expected.

Versions

  • next-pwa: 5.5.5
  • next: 12.2.3

How To Reproduce

Steps to reproduce the behavior:

  1. Setup a fresh installation of next with next-pwa (following the official next-pwa docs)
  2. run npm run build
  3. See sw.js and workbox-*.js only in .next folder but not in public folder.

Additional Context

next.config.js:

const withPWA = require('next-pwa')

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  pwa: {
    dest: 'public',
    register: true,
  }
}

module.exports = withPWA(nextConfig)

mrmonat avatar Jul 28 '22 09:07 mrmonat

5.5.4 only works when we provide a version in package.json like "5.5.4" and the same issue is repro for version: "^5.5.4"

tanaytoshniwal avatar Jul 28 '22 13:07 tanaytoshniwal

Same issue. next version 12.2.3 and next-pwa 5.5.4 not generating files.

Temp fix by copying files to .next folder and serve as file

dymarchyk avatar Jul 29 '22 12:07 dymarchyk

same issue...

Same problem here !!!

Gabrielpdev avatar Jul 29 '22 13:07 Gabrielpdev

Temp fix: downgrade to 5.4.0v

Solved by leaving the config empty:

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

module.exports = withPWA({  
});

norbert-mosinski avatar Jul 29 '22 21:07 norbert-mosinski

Same problem +1

agustints avatar Jul 31 '22 01:07 agustints

Solved by leaving the config empty:

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

module.exports = withPWA({  
});

Tried but still the same issue

timmapuramreddy avatar Aug 01 '22 17:08 timmapuramreddy

Temp fix: downgrade to 5.4.0v

Nextjs with 12.2.3 and PWA 5.4.0 is not working, still same issue

timmapuramreddy avatar Aug 01 '22 17:08 timmapuramreddy

Downgrade to [email protected]

ghost avatar Aug 01 '22 18:08 ghost

I just downgraded to [email protected] with [email protected] And working fine for me.

im-tridevsharma avatar Aug 02 '22 07:08 im-tridevsharma

Next-pwa 5.5.5 have bug Please downgrade to 5.5.4 it will work

Thank you everyone

priyansharma avatar Aug 03 '22 11:08 priyansharma

I downgraded and still not wroking

juniorbatistadev avatar Aug 05 '22 04:08 juniorbatistadev

image

Try with fresh approach.

priyansharma avatar Aug 05 '22 04:08 priyansharma

Hi everyone. Need to remove this symbol ^ in next-pwa": "^5.5.4" and install version 5.5.4

Igrey1321 avatar Aug 05 '22 09:08 Igrey1321

Hi everyone. Need to remove this symbol ^ in next-pwa": "^5.5.4" and install version 5.5.4

Yeah, I figured out this later. Thanks!

juniorbatistadev avatar Aug 05 '22 12:08 juniorbatistadev

Could this be fixed soon?

meabed avatar Aug 11 '22 20:08 meabed

Downgrade to [email protected]

This approach worked for me as well.

mrminnkhantnaing avatar Aug 13 '22 17:08 mrminnkhantnaing

I just downgraded to [email protected] with [email protected] And working fine for me.

This works for me "next-pwa": "5.5.4",

sidd1707 avatar Aug 17 '22 10:08 sidd1707

Same problem ...

Luskan777 avatar Aug 19 '22 03:08 Luskan777

None of the versions working, tried all... "next": "^12.2.5"

Jonathan-Vandenberg avatar Aug 21 '22 11:08 Jonathan-Vandenberg

Guyz Just install [email protected] .

syed-ammad avatar Aug 21 '22 18:08 syed-ammad

@shadowwalker is there any final resolution for this? The only "solution" mentioned in this thread is downgrading to 5.5.4, which seems to be incompatible with the new config format in next.config.js described in next-pwa documentation. And next-pwa is on 5.6.0 now...

jacobjove avatar Sep 22 '22 08:09 jacobjove

@iacobfred it looks like https://github.com/shadowwalker/next-pwa/pull/372 fixed this, so the latest next-pwa version should work fine.

Yorkshireman avatar Sep 22 '22 11:09 Yorkshireman

@Yorkshireman thanks. I just realized that the problem was actually with my build process in my multistage Dockerfile. I was copying the public dir from the host rather than from the builder stage, so it didn't include the service worker files that were generated during the builder stage.

jacobjove avatar Sep 22 '22 16:09 jacobjove

I still have the same problem with next 13.4 and next-pwa ^5.6.0

famdude avatar Aug 05 '23 14:08 famdude

Had the same issue with ^5.6.0. Adding the manual copying to package.json seemingly fixed that:

"postbuild": "cp build/sw.js build/workbox-* public/",

8kto avatar Feb 26 '24 23:02 8kto