Search code examples
javascriptangularservice-workerangular-service-worker

Failed to register a ServiceWorker for scope angular


I know there are many solutions available to this question and some solutions don't fit angular and some solutions not working. I am following this blog to achieve the add to Homescreen feature and I did exactly what is there in that blog and I got the error Failed to register a ServiceWorker for scope ('http://localhost:3000/') with the script ('http://localhost:3000/service-worker.js'): The script has an unsupported MIME type ('text/html'). and then I tried moving the service-worker.js to app folder and got the same error. I have created service-worker.js in the src folder and script mentioned in the blog posted in index.html. I am working on this for 2 days. any help is very much appreciated. thank you


Solution

  • I moved the service-worker.js to the assets folder and changed the path navigator.serviceWorker.register('/assets/service-worker.js'). it worked !!