shadowwalker / next-pwa

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

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

Open marcofranssen opened 2 years ago

marcofranssen commented 2 years ago

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

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
marcomontalbano commented 2 years ago

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

marcofranssen commented 2 years ago

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.

SmartMan1226 commented 2 years ago

having the same issue after upgrading to 5.5.5.

marcofranssen commented 2 years ago

having the same issue after upgrading to 5.5.5.

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

mmalomo commented 2 years ago

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?

marcofranssen commented 2 years ago

excellent! when would that be?

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

mrrhak commented 2 years ago

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.

willianrr commented 1 year ago

image

Hi guys, try to add require and export.

PWA: 5.6.0 Next.js: 12.2.3

willianrr commented 1 year ago

ignore webpack config

matthiasprieth commented 1 year ago

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 commented 1 year ago

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)
);