Failed to register a ServiceWorker -- serving CRA through Node / Express
See original GitHub issueIs this a bug report?
Yes
Can you also reproduce the problem with npm 4.x?
Yes
Which terms did you search for in User Guide?
Error during service worker registration: DOMException: Failed to register a ServiceWorker: The script has an unsupported MIME type (‘text/html’).
register service worker
service worker
Environment
node -v
: v8.1.2npm -v
: 4.6.1yarn --version
(if you use Yarn): 1.0.2npm ls react-scripts
(if you haven’t ejected): 1.0.13
Then, specify:
- Operating system: MacOS Sierra
- Browser and version (if relevant): Google Chrome
Steps to Reproduce
(Write your steps here:)
- go here: https://swtest.quantfive.org/
- Inspect element
- View error
Expected Behavior
Register a service worker
Actual Behavior
The script has an unsupported MIME type ('text/html').
/service-worker.js Failed to load resource: net::ERR_INSECURE_RESPONSE
Error during service worker registration: DOMException: Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html').
Reproducible Demo
Go here to this website: https://swtest.quantfive.org/
Repo Here: https://github.com/lightninglu10/react-sw-test
I’m serving create-react-app through express. I’m forwarding all requests to Index.html and I’m deploying this via Docker & AWS Elastic Beanstalk. Not sure what the error is but I’d like to have a service worker running.
It’s not a front end issue as I’m running the bare bones CRA. I think it may have something to do with serving through express.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top Results From Across the Web
Getting error in browser - Failed to register a ServiceWorker ...
The CRA service worker is disabled by default (hence the serviceWorker.unregister() line). By removing the unregister line, ...
Read more >Using Service Workers with create-react-app - Bits and Pieces
To register the service worker, navigate to the src/index. js file, and look for the following line: serviceWorker.
Read more >Using Service Workers - Web APIs | MDN
After activation, the service worker will now control pages, but only those that were opened after the register() is successful. In other words, ......
Read more >PWA with Create React App and service workers
The starter src/service-worker.js file that you added using the cra-template-pwa or ...
Read more >[Solved]-When I try to register a service worker file in react app ...
Coding example for the question When I try to register a service worker file in react app it will give me a reference...
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 FreeTop 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
Top GitHub Comments
Alright, thanks guys, this worked!
for reference, I added
In my express server.
This issue has plagued me for a while on several apps. When building a spa usually you implement a catch-all route like this (hapijs example):
Which means that index.js takes over the service-worker.js route.
So I can imagine that this happens to more people than just me. And the resulting error does not help to find the real reason. Or so it seems to me.
It might help a lot of people to mention the need to explicitely route
service-worker.js
in the readme, maybe here: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#offline-first-considerations