Uncaught (in promise) TypeError:在Chrome中使用next-pwa获取Nextjs P



嗨,我正在研究一个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文件中的pages

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 

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

Uncaught (in promise) TypeError: Failed to fetch

和我真的不知道为什么,运行应用程序在开发模式与npm运行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

有人能帮我吗?

我使用Chrome89和Workbox6.1.1遇到了同样的错误。
更新Chrome到90(和Workbox到6.1.5)后,这个错误消失了。

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

最新更新