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

sw.js and workbox-*.js do not end up in public folder

Open marcofranssen opened this issue 2 years ago • 11 comments

Summary

When defining following config in my next.config.js the files sw.js and workbox-*.js do not end up in the public folder as explained in the README.md that states if using Nextjs 9 or newer the files will be there. Instead I do see those files end up in the .next folder.

My config looks like:

module.exports =   withPWA({
  pwa: {
    dest: "public"
  }
});

Versions

  • next-pwa: 5.5.5
  • next: 12.2.4

How To Reproduce

Steps to reproduce the behavior:

$ yarn build
yarn run v1.22.19
$ next build
info  - Loaded env from /Users/marco/code/priv/nextjs-blog/.env
info  - SWC minify release candidate enabled. https://nextjs.link/swcmin
Generated 76 documents in .contentlayer
info  - Linting and checking validity of types  
> [PWA] Compile server
> [PWA] Compile client (static)
> [PWA] Auto register service worker with: /Users/marco/code/priv/nextjs-blog/node_modules/next-pwa/register.js
> [PWA] Service worker: /Users/marco/code/priv/nextjs-blog/.next/sw.js
> [PWA]   url: /sw.js
> [PWA]   scope: /
> [PWA] Compile server
[BABEL] Note: The code generator has deoptimised the styling of /private/var/folders/lr/ctz75x8s1r39qp_y7flj6p2m0000gp/T/6f95f768c8708c926b774c8de4734e97/sw.js as it exceeds the max of 500KB.
info  - Creating an optimized production build  
info  - Compiled successfully
info  - Collecting page data  
info  - Generating static pages (192/192)
info  - Finalizing page optimization 

Expected Behaviors

The files end up in public.

Screenshots

N.A.

Additional Context

Also notice the BABEL Note in the log above. Maybe it makes sense to switch from Babel to vercel/ncc to bundle the service worker.

The rootcause is this line https://github.com/shadowwalker/next-pwa/blob/master/index.js#L56

-      } = pwa
+      } = nextConfig.pwa

marcofranssen avatar Aug 11 '22 09:08 marcofranssen

Hi @marcofranssen, there's another thread that suggest to downgrade to 5.5.4 #378 This #372 should solve the issue.

marcomontalbano avatar Aug 11 '22 11:08 marcomontalbano

I fixed 5.5.5 release in #384. Already tested on my personal blog. Basically 1 line of code was missing and one had to be adjusted. All the rest in this PR is code cleanup.

marcofranssen avatar Aug 11 '22 12:08 marcofranssen

having the same issue after upgrading to 5.5.5.

SmartMan1226 avatar Aug 16 '22 20:08 SmartMan1226

having the same issue after upgrading to 5.5.5.

Correct, my fix has to be released as a 5.5.6.

marcofranssen avatar Aug 17 '22 12:08 marcofranssen

having the same issue after upgrading to 5.5.5.

Correct, my fix has to be released as a 5.5.6.

excellent! when would that be?

mmalomo avatar Aug 17 '22 19:08 mmalomo

excellent! when would that be?

I hope as soon as possible. Depends on the maintainer of this repo.

marcofranssen avatar Aug 18 '22 13:08 marcofranssen

I hope as soon as possible. Depends on the maintainer of this repo.

Thank you. I have tried your PR and it works well. While this PR is not yet merged and public release everyone can try this:

"dependencies": {
    "next-pwa": "marcofranssen/next-pwa#fix-pwa-config",
}

Hope it will help you.

mrrhak avatar Aug 19 '22 03:08 mrrhak

image

Hi guys, try to add require and export.

PWA: 5.6.0 Next.js: 12.2.3

willianrr avatar Nov 09 '22 00:11 willianrr

ignore webpack config

willianrr avatar Nov 09 '22 00:11 willianrr

same problem here.

next-pwa versions tried: 5.5.4, 5.5.5, 5.6.0 next version: 11.1.0 image

Don't know what to do anymore.

matthiasprieth avatar Nov 16 '22 12:11 matthiasprieth

works now after rewriting the config a bit more the way @willianrr suggested. Thx for mentioning it, would have never seen it in the documentation. Cause no upgrade-docs, no warnings, no errors. Nothing.

my config (might be different for others)

const withPWA = require("next-pwa")({
    dest: "public",
    register: true,
    skipWaiting: true,
    disable: process.env.NODE_ENV === "development",
})
...
module.exports = withConfig(
    withPlugins([[withPWA, withBundleAnalyzer]], withNextein, nextConfig)
);

matthiasprieth avatar Nov 17 '22 16:11 matthiasprieth