I'm writing my first Progressive Web App for some experience with the concept. The web app is written in Kotlin.js and the ServiceWorker is too. When running the app I get this error
Uncaught Error: Error loading module 'serviceWorker'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'serviceWorker'
.
at serviceWorker.js:2`. How and why would 'kotlin' be missing as a dependency, when it is loaded from a kotlin app, that already is using kotlin as a dependency? given how the application is set up? Is a service worker unable to access the same dependencies as the file loads the service worker?
Service workers operate in their own environment. A different namespace. The DOM cannot be accessed by a serviceworker, so the none of the definitions from the module loading the service worker are available to the service worker.
One simple solutions is to have a js file with both kotlinjs and the service worker code in the one file.