CRA Service worker not working in production

Viewed 54

Hello and thanks in advance for any help. I got a service-worker up and running with my react-app, it runs perfectly on local builds and when deployed from Azure pipelines as well. Problem is in production, which is deployed via Cloudflare, the service worker throws this error in console and cannot figure out why: "Uncaught (in promise) bad-precaching-response: bad-precaching-response :: [{"url":"https://example.com/static/media/getFetch.xxxxxxxxxxxxx.cjs","status":404}]"

Now the said file "getFetc.xxxx.....cjs" seems to be there under static/media/ build files Any suggestions would be welcome!

2 Answers

reason being "getFetc.xxxx.....cjs" this is a static file so you have to mention a rule in your web.config file ,so that this particular file is processed.

Add following line in your web.config file :

 <staticContent>
    <mimeMap fileExtension=".cjs" mimeType="text/javascript" />
 </staticContent>

Hope this will help you..!

Ok, problem solved, and in our case it was actually an error in the server not serving the file whne requested, so apparently nothing was wrong client-side

Related