Closed 4cm4k1 closed 3 years ago
I don't think this is related next-offline but rather to workbox-webpack-plugin. Till it gets fixed to go with webpack 5, you could run post-build command using libraries like https://www.npmjs.com/package/replace-in-files-cli
. Something like
"replace-in-files --string=\"autostatic/\" --replacement=\"static/\" \"src/.next/service-worker.js\""
could work.
Thank you for your insight! Your workaround sounds good, too.
I had the same exact issue (with a webpack 5.9.0 & preact setup). This simple option in next.config.js worked for me:
withOffline({
workboxOpts: {
// ...
modifyURLPrefix: { 'autostatic/': '_next/static/' },
}
})
Inspiration for this fix was a comment from a 2017 issue in GoogleChrome/workbox#689.
Maybe, a potential quick fix in the code of this repo would be adding 'autostatic/': '_next/static/',
in packages/next-offline/index.js#L18, like:
const defaultInjectOpts = {
exclude: preCacheManifestBlacklist,
modifyURLPrefix: {
'autostatic/': '_next/static/', // new addition
'static/': '_next/static/',
'public/': '_next/public/',
},
};
@hanford, what do you think?
Hi!
I have a question, which may or may not be related directly to
next-offline
. I'm using the latest canary Next.js, latest Preact, and newly released Webpack 5. I think the latter is what enabled this issue to crop up, and I am wondering if it's an upstream bug in Webpack or incopy-webpack-plugin
, and regardless, how to work around it, for now. It seems that when the SW is generated the paths for precached assets come out starting withautostatic/
rather than_next/static/
(see below), which, of course, causes 404s, which in turn causes Workbox to report abad-precaching-response
(see below). Importantly, all of precached assets 404, and the PWA/SW functionality is effectively broken.Source: https://github.com/4cm4k1/personal-website Live demo: https://anthony.app Build logs: https://anthony.app/logs
Has anyone encountered this yet? Thoughts?
Many thanks, Anthony
Error:
Precached assets array (from
/sw.js
) with incorrect path prefixes: