0

当我Uncaught (in promise) bad-precaching-response: bad-precaching-response :: [{"url":"https://myapp.vercel.app/_error","status":404}]在 vercel 中部署我的应用程序时,我的 next-pwa 应用程序和服务工作者无法正常工作,尽管它在 localhost 中运行良好,没有错误。我在这里遵循了基本用法https://www.npmjs.com/package/next-pwa,但我使用 firebase-messaging-sw.js 来使用 cloud-messaging 以及 sw.js(service worker) 来进行 pwa。目前我也没有上面错误中提到的_error.js。我认为这些事情可能会影响错误,但到目前为止我还没有任何线索。实际上,我曾经将 _error.js 添加到我的项目中,但它没有做出任何改变......有人可以帮忙解决这个问题吗?先感谢您!

根目录下的 next.config.js

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

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

公共目录中的 manifest.json(图标在公共目录下的图标目录中)

{
  "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>
    );
  }
}

包.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"
  }
}

4

1 回答 1

1

此问题已通过更新 2021 年 4 月 7 日今天发布的 next-pwa 5.2.0 得到解决。

于 2021-04-07T01:01:54.400 回答