nuxt-community / onesignal-module

OneSignal for Nuxt 2
MIT License
74 stars 8 forks source link

Failed to load serviceworker.js. The script has unsupported mimetype #18

Closed riyaz7us closed 3 years ago

riyaz7us commented 3 years ago

Steps to reproduce

nuxt.config.js

  oneSignal: {
    init: {
      appId: "c07236fb-ec62-458d-9d16-0f15d51409e3",
      allowLocalhostAsSecureOrigin: true,
      cdn: true //Doesn't work even if set to false
    }
  },

build and generate nuxt spa.

Expected Behavior

Onesignal sdk must be setup and ready to use

Actual Behavior

Returns error:

[Service Worker Installation] Installing service worker failed SecurityError: Failed to register a ServiceWorker for scope ('https://mywebsite.com/') with script ('https://mywebsite.com/OneSignalSDKWorker.js?appId=xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx'): The script has an unsupported MIME type ('text/html').

Update: Nuxt does not generate OneSignalSDKWorker.js.

riyaz7us commented 3 years ago

I am using nuxt-laravel package provided by @m2sd to generate spa into laravel directory, which couldn't generate OneSignalSDKWorker.js, simply copying and pasting the file from dist worked fine.

Another weird issue was this error Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope', for which I had to change /sw.js?1603631094416 to /sw.js in OneSignalSDKWorker.js file.