Yes
Yes
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
node -v: v8.1.2npm -v: 4.6.1 yarn --version (if you use Yarn): 1.0.2npm ls react-scripts (if you haven鈥檛 ejected): 1.0.13Then, specify:
(Write your steps here:)
Register a service worker
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').

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.
https://swtest.quantfive.org/service-worker.js needs to resolve the file built by sw-precache. Instead, express is redirecting it to your app index.html.
Oh, is it the service-worker.js in the build dir?
Yeah, the service worker is in the build dir. I serve my app with Koa and have no issues with server worker.
Alright, thanks guys, this worked!
for reference, I added
app.get('/service-worker.js', (req, res) => {
res.sendFile(path.resolve(__dirname, '..', 'build', 'service-worker.js'));
});
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):
server.route({
method: 'GET',
path: '/{path*}',
handler: {
file: 'index.html',
},
})
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
Most helpful comment
Alright, thanks guys, this worked!
for reference, I added
In my express server.