Error: Service worker has an unsupported MIME type ('text/html')
See original GitHub issueDescribe the bug
Using the create-react-app-typescript-pwa template to generate a progressive web app returns the following error when `serviceWorker.register() is called:
index.js:1 Error during service worker registration: DOMException: Failed to register a ServiceWorker for scope ('http://localhost:3000/') with script ('http://localhost:3000/serviceWorker.js'): The script has an unsupported MIME type ('text/html').
- I’m only able to see the error message after I remove the following condition in the
checkValidServiceWorker()
function in./src/serviceWorkerRegistration.ts
:
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
Did you try recovering your dependencies?
Yes
Please paste the output of npm --version
and/or yarn --version
to confirm.
–>
7.6.1
Which terms did you search for in User Guide?
PWA, TypeScript, Workbox, Service worker
Environment
current version of create-react-app: 4.0.3 System: OS: Windows 10 10.0.17763
Steps to reproduce
- Run
npx create-react-app my-app --template cra-template-pwa-typescript
- modify
serviceWorker.unregister()
toserviceWorker.register()
Expected behavior
- Service worker should be registered
Actual behavior
Service worker not registered
Issue Analytics
- State:
- Created 3 years ago
- Reactions:17
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Service Worker registration error: Unsupported MIME type ...
Error during service worker registration: DOMException: Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html ...
Read more >The script has an unsupported MIME type ('text/html')
I get following error: The script has an unsupported MIME type ('text/html'). service worker error DOMException: Failed to register a ...
Read more >ServiceWorker MIME Type Error ('text/html') on register (React)
The current behavior: Service worker does not register due to the below error ... The script has an unsupported MIME type ('text/html'). console....
Read more >Unsupported MIME type ('text/html')-Reactjs - appsloveworld
Coding example for the question Service Worker registration error: Unsupported MIME type ('text/html')-Reactjs.
Read more >The script has an unsupported MIME type ('text/js')
[This thread is closed.] I am getting error in the browser console The script has an unsupported MIME type ('text/js') and also getting…...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Given this issue was encountered on Windows and seems to match the symptoms we experienced on Windows I’m wondering if this PR would be relevant: https://github.com/facebook/create-react-app/pull/11640
my setup is an unejected
create-react-app
application, built using the vanilla javascript variant of thepwa
package.i’m not sure anymore that the problem can be resolved by manually copying the file. i believe that’s the job of the workbox plugin (that eventually receives this file’s path), but for some reason it’s blocked in development (i presume due known issues with the devserver).
can’t help much more 🤷