1

I am using create-react-app npm to install react js application. I am trying to use firebase in the project. I am following firebase integration in reactjs tutorial. I have done all things correctly. But I am not certain where is webpack config file. 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. 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?

user254153
  • 1,855
  • 4
  • 41
  • 84

1 Answers1

0

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. To solve this, you need to catch the service-worker file before it goes to the index by default.

yamilelias
  • 305
  • 2
  • 16