javascript - 未捕获( promise )TypeError : Failed to fetch Nextjs PWA using next-pwa in Chrome

标签 javascript google-chrome next.js progressive-web-apps next-pwa

您好,我正在开发 Nextjs 项目,我尝试使用 next-pwa 将其转换为 PWA,首先我创建了 next.config.js

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

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

然后创建 manifest.json

{
  "name": "PRONTO APP",
  "short_name": "PRONTO",
  "icons": [
    {
      "src": "/icon.png",
      "sizes": "128x128",
      "type": "image/png"
    },
    {
      "src": "/icon-512x512.png",
      "sizes": "512x512",
      "type": "image/png"
    }
  ],
  "theme_color": "#FFFFFF",
  "background_color": "#FFFFFF",
  "start_url": "/",
  "display": "standalone",
  "orientation": "portrait"
}

然后我在页面的 de _document 文件中添加元数据

import Document, { Html, Head, Main, NextScript } from "next/document";

class MyDocument extends Document {
    render() {
        return (
            <Html>
                <Head>
                    <link rel="manifest" href="/manifest.json" />
                    <link rel="apple-touch-icon" href="/icon.png" />
                    <meta name='theme-color' content="#fff" />
                </Head>
                <body>
                    <Main />
                    <NextScript />
                </body>
            </Html>
        );
    };
}

export default MyDocument;

但是当我运行时:

npm build dev 
npm start 

在 Google Chrome 中,我的 PWA 工作正常,但在控制台中我收到此错误: 在其他浏览器中不会出现此错误

未捕获( promise )TypeError:获取失败

我真的不知道为什么,在 dev mod 中使用 npm run dev 运行应用程序,我在 chrome 中收到以下消息:

workbox Router is responding to: /
workbox Network request for '/' threw an error. TypeError: Failed to fetch
workbox Using NetworkOnly to respond to '/'
Uncaught (in promise) TypeError: Failed to fetch

这是我的公用文件夹结构:

/public
-/fonts
-/images
-favicon.ico
-icon-512x512.png}
-icon.png
-manifest.json
-sw.js

我试图在这个视频中做同样的事情。 https://www.youtube.com/watch?v=8enp-acPbRE

谁能帮帮我

最佳答案

我在使用 Chrome 89 和 Workbox 6.1.1 时遇到了同样的错误。
将 Chrome 更新到 90(并将 Workbox 更新到 6.1.5)后,此错误消失。

参见相关主题:https://github.com/GoogleChrome/workbox/issues/2749

关于javascript - 未捕获( promise )TypeError : Failed to fetch Nextjs PWA using next-pwa in Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66556441/

相关文章:

reactjs - CSVLink 在 `react-csv` npm 包中生成 HTML 而不是 CSV

javascript - 如何一个一个地同时加载和渲染数据

android - 在 ubuntu 17.04 上使用 LG K10 进行调试

javascript - 确定 Chrome 扩展免费试用何时结束

javascript - Google Chrome 重复 JavaScript 'focus' 事件

next.js - 如何将 Tailwind CSS 滚动平滑类添加到 Next.js

reactjs - 我可以将 NextJS 放在 localhost/next 等子文件夹中吗?

javascript - Liferay 6.2 表单验证问题

javascript - 如何重复使用小型 html 标记?

javascript随机var数组图像