Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script express express

Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script


you could use the full url path for the registration for example:

navigator.serviceWorker.register('ScriptsFolder/subFolder/sw.js')


The only way I have found to solve the TypeError issue when starting a nodejs service worker is to put the service worker script in the root directory of your application, in my case the root of my Amazon EC2 web server.

Wish the error message was more descriptive, TypeError is not terribly helpful. But this fix worked for me.