I have a react tsx project set up already. I am attempting to make it a PWA. In order to do this I need to add service workers. I added service workers in the src folder but am receiving this error when I run firebase deploy
The script has an unsupported MIME type ('text/html'). react_devtools_backend_compact.js:2367 Service Worker registration failed: DOMException: Failed to register a ServiceWorker for scope ('/') with script.... The script has an unsupported MIME type ('text/html').
I am hosting my app on firebase
this is my index.tsx in the src folder
import React from "react"
import ReactDOM from "react-dom/client"
import "./index.css"
import App from "./App"
import reportWebVitals from "./reportWebVitals"
import * as serviceWorker from "./serviceWorker"
// import "bootstrap/dist/css/bootstrap.min.css"
// import { AuthProvider } from "./AuthContext"
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement)
root.render(
<React.StrictMode>
{/* <AuthProvider> */}
<App />
{/* </AuthProvider> */}
</React.StrictMode>
)
serviceWorker.register()
reportWebVitals()
this is my serviceWorker.js file
export function register() {
if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
navigator.serviceWorker
.register("/service-worker.js")
.then((registration) => {
console.log("Service Worker registered with scope:", registration.scope)
})
.catch((error) => {
console.error("Service Worker registration failed:", error)
})
})
}
}
export function unregister() {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.ready
.then((registration) => {
registration.unregister()
})
.catch((error) => {
console.error("Service Worker unregistration failed:", error)
})
}
}
this is my manifest json file
{
"name": "Your App",
"short_name": "your-app",
"description": "fun app to use",
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#007bff",
"icons": [
{
"src": "./app-icon.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "./app-icon.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
I first do npm run build and then firebase deploy. Then I see the error. Any clarity on this would be helpful.
The manifest.json file and the serviceWorker file are both in the same src folder as the index.tsx file.