Expo: How to fix web push notification in development when accessing throw localhost (and how to fix the `localhost` service worker)?

I am using Expo SDK Version: 36 to generate a PWA.

  • curl http://$LOCAL_IP:19006/expo-service-worker.js: OK 200
  • curl http://localhost:19006/expo-service-worker.js: FAIL => Instead of serving expo-service-worker.jsit serve the static assetindex.html`.

enter image description here
It cause the following error in the console:

Failed to register service-worker DOMException: Failed to register a ServiceWorker for scope ('http://localhost:19006/') with script ('http://localhost:19006/expo-service-worker.js'): The script has an unsupported MIME type ('text/html').

The file expo-service-worker.js is not served and this is problematic when you must implement web push notification because only localhost can work without it when site is not served with HTTPS.

Related issues:

How can I fix it?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.