[英]firebaseerror: Failed to register a ServiceWorker
I am using create-react-app npm to install react js application. 我正在使用create-react-app npm安装react js应用程序。 I am trying to use firebase in the project.
我正在尝试在项目中使用Firebase。 I am following firebase integration in reactjs tutorial.
我正在reactjs教程中关注firebase集成 。 I have done all things correctly.
我正确地做了所有事情。 But I am not certain where is webpack config file.
但是我不确定webpack配置文件在哪里。 I tried inserting
我尝试插入
const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
plugins: [
….
new ServiceWorkerWebpackPlugin({
entry: path.join(__dirname, './firebase-messaging-sw.js'),
})
]
Above code snippet to node_module/react-scripts/scripts/webpack.config.dev.js. 上面的代码段为node_module / react-scripts / scripts / webpack.config.dev.js。 But cannot get working.
但是无法工作。
I am upto asking for permission to user and after allowing the permission I see the following error. 我要向用户请求权限,并且在允许该权限后,我看到以下错误。
browserErrorMessage : "Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html')." code:"messaging/failed-serviceworker-registration" message:"Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html').
What is the error related to and how to solve it? 与错误相关的是什么以及如何解决?
You can fin the answer explained here . 您可以找到此处说明的答案。 What happens is that any requests for unknown text files initially get redirected to index.html, and therefore return with the MIME type of
text/html
. 发生的情况是,对未知文本文件的任何请求最初都会重定向到index.html,并因此以
text/html
的MIME类型返回。 To solve this, you need to catch the service-worker file before it goes to the index by default. 为了解决这个问题,您需要在默认情况下在进入索引之前捕获service-worker文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.