I got Uncaught (in promise) bad-precaching-response: bad-precaching-response :: [{"url":"https://myapp.vercel.app/_error","status":404}]
with my next-pwa app and service worker doesn't work, when deploying my app in in vercel, though it works fine in localhost with no error.
I followed basic usage in here https://www.npmjs.com/package/next-pwa, but I use firebase-messaging-sw.js to use cloud-messaging as well as sw.js(service worker) for pwa. Also currently I don't have _error.js, which is mentioned in the above error. I thought those things might influence the error but I have no clue so far. Actually I added _error.js to my project once but it didn't make any change... Can anyone help to solve this? Thank you in advance!
next.config.js in root directory
const withPWA = require("next-pwa");
module.exports = withPWA({
pwa: {
dest: "public",
},
});
manifest.json in public directory (icons are in icons directory, which is under public dir)
{
"name": "myapp",
"short_name": "myapp",
"description": "myapp",
"start_url": "/",
"display": "standalone",
"background_color": "#fff",
"theme_color": "#fff",
"orientation": "any",
"icons": [
{
"src": "/icons/android-chrome-36x36.png",
"sizes": "36x36",
"type": "image/png"
},
,,,,,,,,,,,,,,(some more icons),,,,,,,,,,,,,,
{
"src": "/icons/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
_document.js
import Document, { Html, Head, Main, NextScript } from "next/document";
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx);
return { ...initialProps };
}
render() {
return (
<Html>
<Head>
<meta
name="msapplication-square70x70logo"
content="/icons/site-tile-70x70.png"
/>
<meta
name="msapplication-square150x150logo"
content="/icons/site-tile-150x150.png"
/>
<meta
name="msapplication-wide310x150logo"
content="/icons/site-tile-310x150.png"
/>
<meta
name="msapplication-square310x310logo"
content="/icons/site-tile-310x310.png"
/>
<meta name="msapplication-TileColor" content="#000" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="#000" />
<meta name="apple-mobile-web-app-title" content="myapp" />
<link
rel="apple-touch-icon"
sizes="180x180"
href="/icons/apple-touch-icon-180x180.png"
/>
<meta name="application-name" content="myapp" />
<meta name="theme-color" content="#fff" />
<meta name="description" content="myapp" />
<link rel="icon" sizes="192x192" href="/icons/icon-192x192.png" />
<link rel="icon" href="/icons/favicon.ico" />
<link rel="manifest" href="/manifest.json" />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
package.json
{
"name": "myapp",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"@reduxjs/toolkit": "^1.5.0",
"@tailwindcss/aspect-ratio": "^0.2.0",
"@tailwindcss/forms": "^0.2.1",
"@tailwindcss/line-clamp": "^0.2.0",
"@tailwindui/react": "^0.1.1",
"autoprefixer": "^10.2.4",
"firebase": "^8.2.5",
"localforage": "^1.9.0",
"moment": "^2.29.1",
"next": "^10.1.2",
"next-pwa": "^5.1.4",
"nookies": "^2.5.2",
"nprogress": "^0.2.0",
"postcss": "^8.2.4",
"react": "17.0.1",
"react-dates": "^21.8.0",
"react-dom": "17.0.1",
"react-flip-move": "^3.0.4",
"react-redux": "^7.2.2",
"tailwindcss": "^2.0.2",
"terser-webpack-plugin": "^5.1.1"
}
}
This issue was solved by updating next-pwa 5.2.0, released today, 7th Apr, 2021.